Session Tutorial Two

Source: Internet
Author: User
Tags garbage collection session id php script

For additional features in Phplib and the use of other functions related to sessions, you can refer to the manuals it brings, or to the online documentation on its website. It's home in http://phplib.netuse.de/index.PHP3. PHP4 's session implementation mostly from Phplib learned, it also relies on cookies to save the session ID, with the file system to save variables (by default). Therefore, its session variable cannot save the object (in fact, it can save the object's content, but it doesn't make sense because it is stored on disk, not a live object, at best, the object corpse.) However, this is not too restrictive, and in most cases we just need to save the variable. Of course you can also save the session in the database, and in the next section we'll talk about how to save the session in the database. There is more session support in PHP4 than PhP3, so there are also more session configuration options in php.ini files. Let's take a look at the role and significance of each of the following:

[Session]
Session.save_handler = files; Handler used to Store/retrieve data (save session variable with what, by default)
Session.save_path = c:/temp; Argument passed to Save_handler (save the directory for the session variable, under Linux/unix for/TMP, under win for your directory)
; In the case of files, this is the
; path where data files are stored
Session.use_cookies = 1; Whether to use cookies (whether cookies are used, of course, there is no choice under win)
Session.name = Phpsessid
; Name of the session (the name of the cookie that is used by default session, not recommended)
; is used as cookie name
Session.auto_start = 0; Initialize session on request startup (if session is automatically enabled, you do not have to call the Session_Start () function on every page when you are 1 o'clock)
Session.cookie_lifetime = 0; Lifetime in seconds of cookie (sets the time, in seconds, to save the cookie after it is sent to the browser.) The default value is 0, which means until the browser closes. )
; Or if 0, until browser is restarted
Session.cookie_path =/; The path the cookies are valid for (cookies) (Cookies valid path)
Session.cookie_domain =; The domain the cookie is valid for (cookies valid domain name)
Session.serialize_handler = PHP; Handler used to serialize data, which defines the identity of the serialized data, is used only within the WDDX module or PHP. The default value is PHP)
; PHP is the standard serializer of PHP
session.gc_probability = 1; Percentual probability that (set each temporary file to start processing (GC, garbage collection) processing probability. The default value is 1. )
; ' Garbage collection ' process is started
; On every session initialization
Session.gc_maxlifetime = 1440; After this number of seconds, stored (sets the surviving seconds before the temporary file that holds the session is purged)
; Data would be seen as ' garbage ' and
; Cleaned up by the GC process
Session.referer_check =; Check HTTP Referer to invalidate (determines whether the session code referenced to the client is deleted.) Sometimes it is set to not delete when security or other considerations occur. The default value is 0. )
; Externally stored URLs containing IDs
session.entropy_length = 0; How many bytes to read from the file (sets the number of digits that the session reads from high entropy resources.) The default value is 0.)
Session.entropy_file =; Specified the session ID (set session code when setting up, use an external high entropy value resource or file to build, such as/dev/random or/dev/urandom on UNIX systems. )
; Session.entropy_length = 16
; Session.entropy_file =/dev/urandom
Session.cache_limiter = NoCache; Set to {nocache,private,public} to (setting session buffering limit)
; Determine HTTP caching aspects
Session.cache_expire = 180; Document expires after n minutes (documents are valid for minutes)

Under the Windows platform, the previous version of PHP4.01PL2 will have an error after setting Session.save_path, which is a bug in PHP that has been modified PHP4.01PL2 and later. If you use the previous version, you can set Session.save_path to "./", or set to "/temp", and in the current packing directory where you put the PHP script to build a directory named temp (my php script is placed under D:apachehtdocs, Then I build a directory for temp in D: the packing directory.
The functions for session in PHP4 are mainly as follows:

Session_Start: Initializes the session, which needs to be invoked at the beginning of each page of the session.
Session_destroy: End session, at the end of the session to tune.
Session_name: Accesses the current session name.
Session_module_name: Accessing the current session module.
Session_save_path: Accesses the current session path.
SESSION_ID: Accesses the current session ID number.
Session_register: Registers a new session variable.
Session_unregister: Deletes the registered session variable.
Session_is_registered: Checks whether the session variable is registered.
Session_decode:session data decoding.
Session_encode:session data encryption.

Normally we just need to call three functions.
namely Sesssion_start (), Session_register (), session_is_registered ().
Call the Session_Start () function at the very beginning of each page where you need to use the session.
A typical page that uses the session is as follows:
<?session_start ()?>
....
<body>
?
$var = "Hello";
Session_register ("var")//Register $var variable, note that there is no $ symbol


if (session_is_registered ("var"))//Check whether the variable is registered
echo "Haha, registered!";
Else
echo "Sorry, not yet registered!";

?>
</body>

 

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.