PHP and ASP sessions

Source: Internet
Author: User
Tags php session
PHP and ASP sessions are enabled and need to be used. you can assign values directly!
However, PHP must be started with session_start () to assign values. (Except for php. ini settings that have been changed !)


In terms of expiration time settings, ASP settings are more flexible. the default value is 20 minutes. to customize the settings, use session. timeout = time interval!
However, in PHP, the default value is 24 minutes, and this time needs to change the PHP. INI settings, but not everyone can control it.
Today, I saw an article about php SESSION usage getting started. I saw a function: session_set_cookie_params (); he must use it before session_start!
Example:

// Save for one day
$ LifeTime = 24*3600;
Session_set_cookie_params ($ lifeTime );
Session_start ();
$ _ SESSION ["admin"] = true;
?>

However, it seems that the browser is not very cold: using the session_set_cookie_params () function in IE 6.0 may cause problems in setting cookies!
It does not matter. We can use SESSION and COOKIE in combination for verification:
Example:

Session_start ();
// Save for one day
$ LifeTime = 24*3600;
Setcookie (session_name (), session_id (), time () + $ lifeTime ,"/");
?>




In ASP, sessions are directly stored in the memory, rather than Files. PHP is saved in the temporary folder of the system by default as a file, which does not seem safe, therefore, PHP provides a function that allows you to change its storage location: session_save_path (). This function is also the same as the previous session_set_cookie_params () function () before the function (if it is later, how do you save -_-)!

If the client disables cookies, ASP: I have never seen anyone solve the problem (it is estimated that I am ignorant !)
PHP provides the session_id () function, which is passed through URL. Hao Shuai -_-!
Example:

// Obtain the current Session name. The default value is PHPSESSID.
$ SessionName = session_name ();
$ SessionID = $ _ GET [$ sessionName];
// Use session_id () to set the Session ID
Session_id ($ sessionID );
Session_set_cookie_params ($ lifeTime );
Session_start ();
// Register the 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.