Session control in PHP-session and cookie (data value passing function), sessioncookie

Source: Internet
Author: User

Session control in PHP-session and cookie (data value passing function), sessioncookie

1. After the session log on to the previous page, it has not been operated for a long time. After refreshing the page, You need to log on again.

Features: (1) session is stored on the server;

(2) Each session user (LOGIN) saves a copy;

(3) The session has a default expiration time. (If too many users log on to the session, there will be too much data. Because it is stored on the server, it will put pressure on the server, will be cleared after a certain period of time)

(4) The session can store any type of data.

From the above features, we can conclude that session features comparison.Security. The disadvantage is that it puts some pressure on the server.

(5) When a page needs to use session, you need to add session_start () to the top of the page. To write the session on the top of the page, no code can appear in front of the page. The Code refers to PHP code, you can have HTML code. It is best to develop a habit, put <? Php session_start ();?> At the top of the page. You can write a page once.

(6) operate sessions. A. assign values. B. value.

Assignment:

<? Phpsession_start (); // The session start tag, which is written at the top.?> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Valid value:

The value can be set on any page. For example, when you log on to the page, you can assign the username, password name, and other information to $ _ SESSION ["uid"]. on other pages of the same browser, you can obtain the logon name, password name, and other values, provided that the assigned page is opened first. If you open other pages directly, you cannot obtain the values. Then, close the browser and then open it. You must open the value assignment page before obtaining values from other pages.

<? Phpsession_start ();?> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

2. cookie

Features: (1) the cookie is stored on the client, and the browser will clear the browser information.

(2) Each cookie saves one copy.

(3) The cookie does not have a default expiration time.

(4) only strings can be stored.

From the above features, we can conclude that cookies are not secure and do not put pressure on servers.

Session and cookie can be used without special requirements. However, when the security is high, you must select session.

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.