PHP environment setup & session and cookie usage

Source: Internet
Author: User
Tags http cookie php development environment
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. Syntax
setcookie(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




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.