PHP session_id () session_name ()

Source: Internet
Author: User
Tags setcookie

1.session.use_cookies: The default value is "1", which means that SessionID uses a cookie to pass it, whereas the query_string is used to pass
2.session.name: This is the variable name SessionID stored, either a cookie or a query_string to pass, and the default value is "Phpsessid"
3.session.cookie_lifetime: This represents SessionID in the client cookie storage time, the default value is "0", on behalf of the browser is closed, SessionID is void, because of this reason, so the Session can not be used permanently
4.session.gc_maxlifetime: This is the time the session data is stored on the server side, and if this time is exceeded, the session data is automatically deleted.

1. Set "Session.use.cookies" to "1", turn on cookie storage SessionID, but the default value is "1", generally do not need to modify
2. Change "Session.cookie_lifetime" to "3600", representing 1 hours after SessionID void
3. Set "Session.gc_maxlifetime" to the same as "Session.cookie_lifetime", the Session data will be deleted automatically after this time.

<?php
Session_Start ();
Session_register (' num ');
$num + +;
echo "$num";
?>


<?php
Session_Start ();
Session_register (' num ');//register session variable num
if (Isset ($PHPSESSID)) {
session_id ($PHPSESSID);
}//if $phpsessid is set, the SessionID is assigned to $SESSID, otherwise the build SessionID
$PHPSESSID =session_id ();//Get current SessionID
$num ++;//variable num plus 1
Setcookie (' Phpsessid ', $PHPSESSID, Time () +3600)//Save SessionID to Cookie, expire one hour later
echo "$num";//Displays the value of the session variable num
?>
The prototype of the Setcookie function Kusakabe:
int Setcookie (string name,string value,int expire,string path,string domain,int secure);
The meanings of each of these parameters are as follows:
Name: Indicates the names of the cookies to be set
Value: Represents the values of the cookie to be set, and if the value of this parameter is an empty string, the data for the cookie in the browser is deleted.
Expire: Indicates the effective time of the cookie
Path: The associated path for the cookie
Domain: A website that represents a cookie
Secure: This parameter is valid only if HTTPS is required for secure transmission
Setcookie ("User", "Lee", Time () +3600);//cookie with expiration
Setcookie ("User", "Lee", Time () +3600, "/php/");//cookie with path

Session_Start
Initial session
Syntax: Boolean session_start (void);
Return Value: Boolean value
Function type: Data processing
Description: This function initializes a new session, and if the client is already in session, connect to the original session. This function has no arguments and returns a value of true.
Session_destroy
End Session
Syntax: Boolean session_destroy (void);
Return Value: Boolean value
Function type: Data processing
Description: This function ends the current Session. This function has no arguments and returns a value of true.
Session_name
Access current session Name
Syntax: string session_name (string [name]);
return value: String
Function type: Data processing
Description: This function can be used to obtain or reset the current Session name. If no parameter name is given, the name of the session is simply obtained, plus the parameter indicates that the session name is set to the parameter name.
Use Example: The following example is the Session fragment program
<?php
$username = "Guest";
if (Isset ($username)) {
Session_name ($username);
}
echo "You are". Session_name (). "/n";
?>
Session_module_name
Access the current session module.
Syntax: string session_module_name (string [module]);
return value: String
Function type: Data processing
Description: This function can be used to obtain or re-set the current Session of the module. If no parameter module indicates that only the module of the current session is obtained, plus the parameter indicates that the session module is set as the parameter module.

Session_save_path
Access the current session path.
Syntax: string session_save_path (string [path]);
return value: String
Function type: Data processing
Description: This function can get or reset the current path of the Session. If no parameter path indicates that only the path directory name of the current session is obtained, and the parameter path indicates that the session exists on the new path.

session_id
Access the current session code.
Syntax: string session_id (string [id]);
return value: String
Function type: Data processing
Description: This function can be used to obtain or re-set the current storage Session code. If no parameter ID means that only the current session of the code name, plus the parameter indicates that the session code is set to the new specified ID. Both input and return are strings.
Session_register
Registers a new variable.
Syntax: Boolean session_register (string name);
Return Value: Boolean value
Function type: Data processing
Description: This function adds a variable to the current Session in the global variable. The parameter name is the variable name that you want to add. Success returns the True value.
Session_unregister
Delete the registered variable.
Syntax: Boolean session_unregister (string name);
Return Value: Boolean value
Function type: Data processing
Description: This function deletes variables on global variables in the current Session. The parameter name is the variable name that you want to delete. Success returns the True value.
Session_is_registered
Check if the variable is registered.
Syntax: Boolean session_is_registered (string name);
Return Value: Boolean value
Function type: Data processing
Description: This function checks to see if a specified variable has been registered in the current Session. The parameter name is the variable name that you want to check. Success returns the True value.
Session_decode
Session data decoding.
Syntax: Boolean session_decode (String data);
Return Value: Boolean value
Function type: Data processing
Description: This function can decode the Session data. Parameter data is the data to be decoded. Success returns the True value.
Session_encode
Session data encoding.
Syntax: Boolean session_encode (void);
Return Value: Boolean value
Function type: Data processing
Description: This function can encode the Session data and encode the ZEND engine as a hash code. This function has no arguments. Success returns the True value.

PHP session_id () session_name ()

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.