PHP Basic notes



Predefined Variables

PHP's superglobal variables are 
$_SERVER, $GLOBALS, $_REQUEST, $_POST, $_GET, $_FILES, $_ENV, $_COOKIE, $_SESSION.
They are available anywhere withoutscope that is accessible from anywhere.



$_SESSION


session_start();
//use session
$_SESSION["name"] = "session stored";
session_unset();
session_destroy();


COOKIE


Cookies are often used to identify the user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page through a browser, it will send the cookie, too. With PHP, you can both create and retrieve cookie values.

setcookie(name, value, expire, path, domain, secure, httponly);

we retrieve cookie with 
$_COOKIE["name"];

Working with Files

PHP offers a number of functions to use when creating, reading, uploading, and editing files.

$mode = r; // r,w,a,x, r+, w+, a+,x+;
$file =  fopen("filename", $mode);

fwrite($file, "data");
fclose(); //return true onsuccess and false on failure


REF: https://www.sololearn.com/Play/PHP

Share this

Related Posts

Previous
Next Post »