PHP environment setup & session and cookie usage 1. install and integrate the PHP development environment
: Http://www.appservnetwork.com/index.php? Newlang = chinese
Software: appserv-win32-2.5.10.exe
After installation, write the php document in the D: \ AppServ \ www directory.
Eg. http: // localhost/Untitled-5.php
Untitled-5 is the name of the www Directory
2. I learned how to use session and cookie today: I don't know what they do.
Session on the server, cookie on the client (browser)
1 "session usage-information transmission between multiple pages: simply put, the data transmitted on this page is displayed on another page.
Untitled-1.php
SESSION use form section
Untitled-4.php
Use-registration
";}$ _ SESSION [" username "] = $ user; echo" hyperlink test button ";?>
Untitled-5.php
Use-Page 3 verification form
The $ _ POST variable is used to collect the values in the form from method = "post. The action = "welcome. php" (Untitled-4.php) file can now get form data through the $ _ POST variable .. The $ _ POST variable is an array.
$_SESSION["username"]=$user;
Sessions can be assigned values directly without registration. After the value is assigned, another file can get the value of the value through $ _ SESSION.
2. use of cookies-retention period of user logon
Untitled6-. php
Log on to save instance-COOKIE instance
Untitled-7.php
"; Echo" log on again ";} else {switch ($ time) {case 1: $ time = time (); break; case 2: $ time = time () + 60*60; break; case 3: $ time = time () + 60*60*24; break; case 4: $ time = time () + 60*60*24*30; break; case 5: $ time = time () + 60*60*24*30*365; break;} setcookie ("username ", $ username, $ time); // register the user name}?>
Registered user information
"; Echo" COOKIE validity period: "; switch ($ _ POST [" time "]) {case 1: echo" 1 "; break; case 2: echo "2"; break; case 3: echo "3"; break; case 4: echo "4"; break; case 5: echo "5"; break;}?>
Cookie is a variable sent by the server to the browser. the setcookie () function sends an HTTP cookie to the client. Syntaxsetcookie(name,value,expire,path,domain,secure)
In this way, a global cookie variable named name is created. if you need to access the global variable $ _ COOKIE [], you can access the global variable $ _ cookie.
Delete cookie: setcookie ["username"];
The setcookie function must be placed in anyOrBefore