Session tutorial 2. For other functions in PHPlib and the use of other functions related to session, you can refer to its manual or view online documents on its website. Its hometown is phplib. netuse. d. for other functions in PHPlib and the use of other functions related to session, you can refer to its manual or read online documents on its website. It's home in http://phplib.netuse.de/index.PHP3. The session implementation of php4 is mostly learned from phplib. It also uses cookies to save session IDs and uses the file system to save variables (by default ). Therefore, its session variable cannot save objects (in fact, it can save the object content, but it does not make sense, because it is saved on a disk, not a live object, at best, it is the object body .) However, this limit is not too large. In most cases, we only need to save the variable. Of course, you can also save the session in the database. in the next section, we will talk about how to save the session in the database. In php4, the session configuration option is also added to the PHP. ini file because it supports more sessions than php3. Let's take a look at the functions and meanings of each item:
[Session]
Session. save_handler = files; handler used to store/retrieve data (when to save session variables, files are used by default)
Session. save_path = c:/temp; argument passed to save_handler)
; In the case of files, this is
; Path where data files are stored
Session. use_cookies = 1; whether to use cookies (whether to use cookies, of course, there is no choice in win)
Session. name = PHPSESSID
; Name of the session (the cookie name used by the Default session. do not change it)
; Is used as cookie name
Session. auto_start = 0; initialize session on request startup (whether to enable the session automatically. if it is set to 1, you do not have to call the session_start () function on each page)
Session. cookie_lifetime = 0; lifetime in seconds of cookie (set the retention time after the cookie is sent to the browser, in seconds. The default value is 0, indicating that the browser is closed .)
; Or if 0, until browser is restarted
Session. cookie_path =/; the path the cookie is valid for (cookie) (cookie valid path)
Session. cookie_domain =; the domain the cookie is valid for (cookie valid domain name)
Session. serialize_handler = php; handler used to serialize data (define the identifier of the serialized data. This function is only used in the WDDX module or PHP. The default value is PHP)
; Php is the standard serializer of PHP
Session. gc_probability = 1; percentual probability that sets the processing probability of each temporary file start processing (gc, garbage collection. The default value is 1. )
; 'Bucket collect' process is started
; On every session initialization
Session. gc_maxlifetime = 1440; after this number of seconds, stored (set the number of seconds before the temporary file for saving the session is cleared)
; Data will be seen as 'garbage' and
; Cleaned up by the gc process
Session. referer_check =; check HTTP Referer to invalidate (determines whether to delete the session code referring to the client. Sometimes it is set not to be deleted for security or other considerations. The default value is 0 .)
; Externally stored URLs containing ids
Session. entropy_length = 0; how many bytes to read from the file (set the number of digits that the session reads from high-entropy resources. The default value is 0 .)
Session. entropy_file =; specified here to create the session id (set the session code to be created using an external high-entropy resource or file, for example,/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 (set session buffer restrictions)
; Determine HTTP caching aspects
Session. cache_expire = 180; document expires after n minutes (document validity period, in minutes)
On windows, php 4.01pl2 and earlier versions may encounter an error after session. save_path is set. this is a php bug and has been fixed in php4.01pl2 and later versions. If you use a previous version, you can set the session. set save_path ". /", or set it to"/temp ", and create a directory named temp under the current root directory where you place the php script (my PHP script is placed under d: apachehtdocs, then I create a directory named temp under the d: root directory ).
The session functions in PHP4 mainly include the following:
Session_start: initialize the session, which must be called at the beginning of each page of the session.
Session_destroy: ends the session and calls it at the end of the session.
Session_name: name of the current session to be accessed.
Session_module_name: Access the current session module.
Session_save_path: the current session path.
Session_id: Access the current session id.
Session_register: registers a new session variable.
Session_unregister: delete the registered session variable.
Session_is_registered: Check whether the session variable is registered.
Session_decode: decodes session data.
Session_encode: session data encryption.
Generally, we only need to call three functions.
That is, sesssion_start (), session_register (), and session_is_registered ().
Call the session_start () function at the beginning of each page of the session,
A typical session page is as follows:
....
$ Var = "hello ";
Session_register ("var"); // register the $ var variable. Note that the $ symbol does not exist.
If (session_is_registered ("var") // check whether the variable is registered
Echo "haha, registered! ";
Else
Echo "sorry, not registered yet! ";
?>
Bytes. It's home in http://phplib.netuse.d...