PHP session tracking and file processing system 1 (43)

WBOY
Release: 2016-08-08 09:23:12
Original
940 people have browsed it

Unregister variables

1. unset ($_SESSION[‘xxx’]) deletes a single session variable, and unset ($_SESSION[‘xxx’]) is used to unregister a registered session variable. Its function 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 feasible way to restore it. Users can also no longer register the $_SESSION variable.
2. $_SESSION=array() deletes multiple session variables
3. session_unset() deletes all session variables

destroy the session

session_destroy() ends the current session and clears all resources in the session. This function will not unset (release) global variables related to the current session, nor will it delete the client's session cookie.
Return value: Boolean value.
Function description: This function ends the current session. This function
has no parameters, and the return value is true.

Note: PHP’s default session is based on cookies. If you want to delete cookies, you must use the setcookie() function.

Case of deleting session

<?<span>php
</span><span>//</span><span> 初始化session.</span><span>session_start();
</span><span>/*</span><span> 删除所有的session变量..也可用
unset($_SESSION[‘xxx’])逐个删除。</span><span>*/</span><span>$_SESSION </span>= array();<span>//</span><span>或session_unset();</span><span>/*</span><span>删除sessinid.由于session默认是基于cookie的,所
以使用setcookie删除包含session id的cookie.</span><span>*/</span><span>if</span><span> (isset($_COOKIE[session_name()])) {
setcookie(session_name(), </span><span>'</span><span>'</span>, time()-<span>42000</span><span>,
</span><span>'</span><span>/</span><span>'</span><span>);
}
</span><span>//</span><span> 最后彻底销毁session.</span><span>session_destroy();
</span>?>
Copy after login

Persistent session

After the request is completed, all registered variables will be automatically serialized (for convenience, saved to the session text file on the server side), and then restored when 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 saved in the session . Including resource variables or objects with circular references (that is, an object passes a reference to itself to another object).

Configuring Session Control

There is a set of session configuration options in the php.ini configuration file that can be set. As follows:
??session.auto_start= 0; Initialize the session when the request starts
??session.cache_expire= 180; Set the session document in the cache to expire after n minutes
??session.cookie_lifetime= 0; Set in seconds The storage time of the cookie is equivalent to setting the expiration time of the Session. When it is 0, it means until the browser is restarted. You can also start session.auto_start=1 in php.ini, so that you don’t need to call it every time before using the session. session_start().

But there are some limitations to enabling this option, if session.auto_start is indeed enabled, you cannot put objects into the session because the class definition must be loaded before starting the session to recreate the object in the session.


??session.cookie_path= / ; The valid path of the cookie

??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 method for saving/retrieving data
??session.save_path= /tmp; Parameter passed to the controller when save_handler is set to a file. This is the path where the data file will be saved.
??session.use_cookies = 1; Whether to use cookies

File processing system

File type

??When the program is running, the program itself and the data are generally stored in the memory. When the program ends, the data stored in the memory is released .

??If you need to save the original data required for program operation or the results generated by program operation for a long time, it must be stored in the form of files on external storage media.

??A file generally refers to a set of related data with a name (file name) stored on external media. Files can be used to save data for a long time and enable data sharing.
??PHP is modeled after the UNIX file system. Therefore, in Windows systems we can only obtain three file types: "file", "dir" or "unknown". In UNIX systems, we can get seven types: 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( ) -- Determine whether the 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 returns false.
??is_executable() -- Determine whether the given file name is executable
Syntax structure: boolis_executable (name)
Return type: Returns true if the file exists and is executable, otherwise returns false.
??is_file( ) -- Determine whether 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( ) -- Determine whether the given file name is a symbolic link
Syntax structure: boolis_link (name)
Return type: Returns true if the file exists and is a symbolic link.
??is_readable( ) -- Determine whether the given file name is readable
Syntax structure: boolis_readable (file name)
Return type: Returns true if the file exists and is readable.
??is_writable() -- Determine whether the given file name is writable
Syntax structure: boolis_writable (file name)
Return type: Returns true if the file exists and is writable.

Properties of the file

The above introduces the PHP session tracking and file processing system 1 (43), including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!