Posts

Showing posts from April, 2016

File Handling In PHP(HOW TO STORE FORM DATA TO A FILE)

PHP FILE HANDLING: PHP Open File - fopen(): A better method to open files is with the fopen() function. PHP Read File - Fread(): The fread() function reads from an open file. PHP Read Single Line - Fgets(): The fgets() function is used to read a single line from a file. PHP Write To File - Fwrite(): The fwrite() function is used to write to a file. r =>         Open a file for read only. File pointer starts at the beginning of the file w=>        Open a file for write only. Erases the contents of the file or creates a new file if it doesn't exist. File pointer starts at the beginning of the file a=>         Open a file for write only. The existing data in file is preserved. File pointer starts at the end of the file. Creates a new file if the file doesn't exist (1)TO   WRITE   A   TEXT  “this is my file”   ...

Sending Email Using Php-Mail-Function

The mail() function allows you to send emails directly from a script. Syntax: mail(to,subject,message,headers,parameters); to    =>   Required. Specifies the receiver / receivers of the email subject =>   Required. Specifies the subject of the email. Note: This parameter cannot contain any newline characters message  =>     Required. Defines the message to be sent. Each line should be separated with a LF (\n). Lines should not exceed 70 characters. headers  =>   Optional. Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (\r\n). Note: When sending an email, it must contain a From header. This can be set with this parameter or in the php.ini file. parameters  =>   Optional. Specifies an additional parameter to the sendmail program (the one defined in the sendmail_path configuration setting). (i....

Setting Cookies With PHP

Create Cookies With  PHP: A cookie is created with the setcookie() function. Syntax setcookie( name, value, expire, path, domain, secure, httponly ); Only the   name   parameter is required. All other parameters are optional. PHP Create/Retrieve A Cookie The following example creates a cookie named "user" with the value "John Doe". The cookie will expire after 30 days (86400 * 30). The "/" means that the cookie is available in entire website (otherwise, select the directory you prefer). We then retrieve the value of the cookie "user" (using the global variable $_COOKIE). We also use the isset() function to find out if the cookie is set: Example <?php $cookie_name = "user"; $cookie_value = "John Doe"; setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day ?> <html> <body> <?php if(!isset($_COOKIE[$cookie_name])) {     echo "Cookie named ...