PHP half way home (4)

Source: Internet
Author: User
Previous article: success! What is Cookie and Session? A: storage mechanism !!! Cookie: from the web page...

Previous: http://www.2cto.com/kf/201205/131555.html


The reason is that the previous BLOG writing system was unsuccessful. I need to understand the basic mechanism.

Start with Cookie and Session!
What is Cookie and Session?
A: storage mechanism !!!
Cookie: the data transmission method from the Web page to the Web page. the Client exists.

Session: a method to ensure that data remains valid on the page.

Session mechanism-tracking users based on a session on a website

Allows users to log on and display information based on their interests.

 

PHP session-a unique session ID to drive.

This ID is an encrypted random number.

The session will be stored on the client during its lifecycle.

Stored in cookies and transmitted through URLs on the Internet


Talk about cookies first
Overview:
A mechanism for storing data on a remote browser to identify and track users

Will exist on the user's hard disk. when the user logs on again, it will read the specific information

Format: user name: @ 网 ]]digital *.txt

Function:
Record Visitor Information

Transfer variables between pages

Store the viewed page in the Cooike folder to speed up re-access.

Usage:
Create: setcookie (name, value, expire, path, domain, secure)

Parameter description

Parameters Description
Name Required. name
Value Required. cookie value
Expire Validity period
Path Server path
Domain Domain name
Secure Whether to transmit data over https
 

Read: $ _ COOKIE ['XXX'] Read

Delete:

Use setcookie (); setcookie ("name", "", time ()-1 );

 

Let's look at the SESSION.
Overview:
Prevent users from logging on to each opened page and using Session

The session is stored on the client, which is more efficient than the cookie during verification (you do not need to go to the Database to check the information every time)

Usage:
Start: session_start ();

Use: $ _ SESSION ['name'] = "Matter ";

Delete:

Unset ($ _ SESSION ['name']); // deletes a single attribute.
Session_destroy (); // delete the entire session and clear all resources!
$ _ SESSION = array (); // delete all sessions

 


From matter605924657

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.