PHP
PHP
Test variables outside the fumetion:
echo "Variable xis: Sx echo "This is an example to show how to include PHP file!
The require() Function The require() function takes all the text in a specified file and copies it into the file that uses the include function. If there is any problem in loading a file then the require() function generates a fatal error and halt the execution of the script. So there is no difference in require() and include() except they handle error conditions. It is recommended to use the require() function instead of include(), because scripts should not continue executing if files are missing or misnamed. You can try using above example with require() function and it will generate same result. But if you will try following two examples where file does not exist then you will get different results.Cont...This is an example to show how to include wrong PHP file!
output This is an example to show how to include wrong PHP file!Cont...This is an example to show how to include wrong PHP file!
output This fime Tilé execution halts and nothing is displayed. NOTE — You may get plain warning messages or fatal error messages or nothing at all. This depends on your PHP Server configuration.Creating Directories in PHP » Anew directory can be created in PHP using the mkdir( function. ° This function takes a path to the directory to be created. » To create a directory in the same directory as your PHP script simply provide the directory name. ¢ To create a new directory in a different directory specify the full path when calling mkdirQ.Cont... Deleting a Directory + Directories are deleted in PHP using the rmdir(O function. ¢ rmdir( takes a single argument, the name of the directory to be deleted. + The deletion will only be successful if the directory is empty. e If the directory contains files or other sub- directories the deletion cannot be performed until those files and sub-directories are also deleted.Read files in PHP ¢ The freadQ) function reads from an open file. + The first parameter of fread() contains the name of the file to read from and the second parameter specifies the maximum number of bytes to read. Example:- Open File in PHP ¢ A better method to open files is with the fopen() function. ° The first parameter of fopen() contains the name of the file to be opened and the second parameter specifies in which mode the file should be opened.| Cont... (| Ee a file for read only. File pointerstarts at the beginning of the file |Open a file for write only. Erases the contents of the file or createsa new file ifit doesn't exist. File jpointer starts at the beginning of the file |Open a file for write only. The existing data in file is preserved. File pointerstartsat theend of the file. Createsa new file if the file doesn't exist (Creates a new file for write only. Returns FALSE and an erroriffile already exists |Open a file for read/write. File pointer startsat the beginning of the file Open a file for read/write. Erases the contents of the file or creates a new file ifit doesn't exist. File ipointer starts at the beginning of the file lOpen a file for read/write. The existing data in ile is preserved. File pointerstartsat the end of the file. Creates a new file if the file doesn’t exist (creates a new file for read/write. Returns FALSE and an error if file already existsPHP Cookies + Acookie is often used to identify a user. ‘What is a Cookie? + Acookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser it will send the cookie too. With PHP, you can both create and rettieve cookie values, Create Cookies With PHP: + Accookie is created with the setcookie( funetion. Syntax + seteookie(name, value, expire, path, domain, secnre, httponty); + 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 "fohn Doe". The cookie will expire after 30 days (66100 * 30). The "/" means that the cookieis available in enfie website (otherwise, select the directory you pref). + Wethen retrieve the value of the cookie "user" (using the global variable $_COOKIE). We also use the isset() function to find outif the cookie is set Note: The setcookie() function must appear BEFORE the tag.Example <2php Scookie_name = "user"; Seookie_valne = "Ton Doe"; setcookie(Scookie_name, Scookie_value, time() + (86400 * 30), "/"; // 86400 = 1 day