PHP session tracking End and file processing system one (43)

Source: Internet
Author: User
Tags php session setcookie

Unregister variables

1, unset ($_session[' xxx ']) Delete a single session variable, unset ($_session[' xxx ") is used to unregister a registered session variable.     Its effect is the same as Session_unregister (). Session_unregister () is no longer used in PHP5.
Note: unset ($_session) This function must not be used, it will destroy the global variable $_session, and there is no viable way to restore it. Users can no longer register $_session variables.
2. $_session=array () delete multiple SESSION variables
3, Session_unset () Delete all session variables

Destroying sessions

Session_destroy () ends the current session and empties all resources in the session. The function does not unset (releases) the global variables associated with the current session, nor does it delete the client's session cookie.
Return value: A Boolean value.
Function Description: This function ends the current session, this function
There are no parameters, and the return value is true.

Note: PHP's default session is cookie-based, and if you want to delete cookies, you must use the Setcookie () function.

Delete a session case

?PHP//initializes the session.session_start ();/*Delete all the session variables: unset ($_session[' xxx ') can also be deleted individually. */$_session= Array ();//or Session_unset ();/*Delete Sessinid. Because the session is cookie-based by default, use Setcookie to delete the cookie that contains the session ID.*/if(Isset ($_cookie[session_name ())) {Setcookie (Session_name ()),' ', Time ()-42000,'/');}//Finally, the session is completely destroyed.Session_destroy ();? >
Persistent session

All registered variables are automatically serialized at the end of the request (for easy saving to the server-side session text file) and then restored when read.
?? 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 saved in the session. Includes a resource variable or an object that has a circular reference (that is, an object passes a reference to itself to another object).

Configuring Session Control

The php.ini configuration file has a set of session configuration options that you can set. As follows:
?? session.auto_start= 0; Initialize session at request startup
?? Session.cache_expire= 180; Set the session document in the cache to obsolete after n minutes
?? Session.cookie_lifetime= 0; Sets the save time of a cookie in seconds, which is equivalent to setting the session expiration time of 0, until 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 () before each use of the session.
However, there are some restrictions on enabling this option, and if you do enable Session.auto_start, you cannot put an object into a session because the class definition must be loaded before starting the session to rebuild the object in the session.

?? Session.cookie_path=/; Valid path for cookies
?? session.cookie_domain=; The valid domain of the cookie
?? Session.name= Phpsessid; The name of the session used in the cookie
?? session.save_handler= files; control mode for saving/retrieving data
?? Session.save_path=/tmp; The parameters that are passed to the controller when the Save_handler is set to a file, which is the path to which the data file will be saved.
?? Session.use_cookies= 1; Whether to use cookies

File Processing SystemFile type

?? When the program runs, the program itself and the data are usually in memory, and when the program is finished, the data stored in memory is freed.
?? If you need to save the original data that the program needs to run for a long time, or the results of the program running, it must be stored as a file on the external storage media.
?? A file generally refers to a set of related data stored on external media that has a name (file name). Files can be used for long-term preservation of data, and to achieve data sharing.
?? PHP is modeled on the Unix file system. So we can only get "file", "dir" or "Unknown" in the Windows system for three types of files. In Unix systems, we have seven types of block, Char, dir, FIFO, file, link, and unknown.
?? You can use the function filetype () to get the specific type of the file.
?? Syntax: string filetype (string filename)

Description of 7 file types in the Liunx system

Is_dir ()--Determines whether a given file name is a directory
Syntax structure: boolis_dir (name)
Return type: Returns True if the file name exists and is a directory, otherwise false.
?? Is_executable ()--determine if the given file name is executable
Syntax structure: boolis_executable (name)
return type: False if the file exists and the executable returns TRUE.
?? Is_file ()--determine if the given file name is a normal file
Syntax structure: boolis_file (name)
Return type: Returns True if the file exists and is a normal file.
?? Is_link ()--Determines whether a given file name is a symbolic connection
Syntax structure: boolis_link (name)
Return type: Returns True if the file exists and is a symbolic connection.
?? Is_readable ()--Determines whether a given file name is readable
Syntax structure: boolis_readable (file name)
Return type: Returns True if the file exists and is readable.
?? Is_writable ()--Determines whether a given file name can be written
Syntax structure: boolis_writable (file name)
Return type: Returns True if the file exists and is writable.

Properties of the file

PHP session tracking End and file processing system one (43)

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.