PHP session tracking and File Processing System (43)

Source: Internet
Author: User
Tags php session
: This article mainly introduces PHP session tracking and File Processing System (43). If you are interested in PHP tutorials, refer to it. Cancel variable

1. unset ($ _ SESSION ['XXX']) deletes a single session variable. unset ($ _ SESSION ['XXX']) is used to unregister a registered session variable. It works the same as session_unregister. Session_unregister () is no longer used in PHP5.
Note: The unset ($ _ SESSION) function is never available. it destroys the global variable $ _ SESSION and there is no feasible way to restore it. You can no longer register the $ _ SESSION variable.
2. $ _ SESSION = array () delete multiple session variables
3. session_unset () deletes all session variables.

Destroy session

Session_destroy () ends the current session and clears all resources in the session. This function does not unset (release) global variables related to the current session, nor delete the client session cookie.
Return value: Boolean value.
Function description: This function ends the current session.
No parameter, and the return value is true,

Note: The default session in PHP is based on cookies. to delete a cookie, you must use the setcookie () function.

Delete a session

<? Php // initialize session. session_start ();/* delete all session variables .. You can also delete unset ($ _ SESSION ['XXX']) one by one. */$ _ SESSION = array (); // or session_unset ();/* delete sessinid. because the session is cookie-based by default, setcookie is used to delete the cookie containing the session id. */if (isset ($ _ COOKIE [session_name ()]) {setcookie (session_name (), '', time ()-42000 ,'/');} // Finally, the session is completely destroyed. session_destroy ();?>

Persistent session

After the request ends, all the registered variables will be automatically serialized (to facilitate the storage to the session text file on the server side) and restored upon reading.
?? Manual encoding and decoding:
?? Session_encode (): Serial Number-encoding
?? Session_decode (): Restore-decode
?? Warning some types of data cannot be serialized and therefore cannot be stored in sessions. Including resource variables or objects with circular references (that is, an object passes a reference pointing to itself to another object ).

Configure session control

The php. ini configuration file contains a set of session configuration options that can be set. As follows:
?? Session. auto_start = 0; initialize the session when the request starts.
?? Session. cache_expire = 180; set the cached session document to expire after n minutes
?? Session. cookie_lifetime = 0; set the cookie retention time in seconds, which is equivalent to setting the Session expiration time. if it is set to 0, it indicates that the browser is restarted.

You can also start session. auto_start = 1 in php. ini, so that you do not need to call session_start () every time before using the session ().
However, enabling this option also has some restrictions. if the session is enabled. auto_start, the object cannot be put into the session, because the class definition must be loaded before the session is started to recreate the object in the session.

?? Session. cookie_path =/; valid cookie path
?? Session. cookie_domain =; valid domain of the cookie
?? Session. name = PHPSESSID; name of the session used in the cookie
?? Session. save_handler = files; control method for saving/retrieving data
?? Session. save_path =/tmp; the parameter passed to the controller when save_handler is set to a file, which is the path to save the data file.
?? Session. use_cookies = 1; whether to use cookies

File processing system

File type

?? When the program runs, the program itself and data are generally stored in the memory. when the program runs, the data stored in the memory is released.
?? If you need to save the raw data required by the program running for a long time, or the results generated by the program running, you must store the data on the external storage media as a file.
?? A file is a collection of related data that is stored on an external media with a name (file name. Data can be stored in files for a long time and shared.
?? PHP is a UNIX file system. Therefore, in Windows, we can only obtain "file", "dir", or "unknown" file types. In UNIX systems, we can obtain seven types: block, char, dir, fifo, file, link, and unknown.
?? You can use the filetype () function to obtain the object type.
?? Syntax: string filetype (string filename)

Description of seven file types in the Liunx system

Is_dir () -- determines whether the specified file name is a directory.
Syntax structure: boolis_dir (name)
Return type: If the file name exists and is a directory, true is returned; otherwise, false is returned.
?? Is_executable () -- determines whether a given file name can be executed
Syntax structure: boolis_executable (name)
Return type: if the object exists and can be executed, true is returned; otherwise, false is returned.
?? Is_file () -- determine whether the given file name is a normal file
Syntax structure: boolis_file (name)
Return type: if the object exists and is a normal object, true is returned.
?? Is_link () -- determines whether a given file name is a symbolic connection
Syntax structure: boolis_link (name)
Return type: true is returned if the object exists and is a symbolic connection.
?? Is_readable () -- determines whether the specified file name is readable.
Syntax structure: boolis_readable (file name)
Return type: Returns true if the object exists and is readable.
?? Is_writable () -- determines whether a given file name can be written.
Syntax structure: boolis_writable (file name)
Return type: If the file exists and can be written, true is returned.

File attributes

The above introduces PHP session tracking and File Processing System 1 (43), including some content, hope to be helpful to friends who are interested in PHP tutorials.

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.