Home  >  Article  >  Backend Development  >  Several supplementary functions about session (transfer_PHP tutorial

Several supplementary functions about session (transfer_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:05:08696browse

​​​​​ Several supplementary functions about session
Under PHP, there are many discussions about session. In fact, there are several functions in PHP4 that we usually don’t notice.
Let me introduce them to you below.
The session_set_save_handler() is really a good thing.
//**********************
session_unset (PHP4 >= 4.0b4)
void session_unset(void);
This The function can set all registered session variables to null. Note that it is not unregister, nor is it the same as destroy.
The following example provides a good explanation of this function.
session_register("a","b","c"); //auto-session-start
$a=1;
$b=2;
$c=3;
session_unregister("a"); //unregistrered $a
echo "A: $a - reg:".session_is_registered("a")."
"; // but the global $a remains
session_unset(); // unsets $b und $c
echo "B:$b - reg:".session_is_registered("b")."
"; // the registration remains !
echo "C:$c - reg:".session_is_registered("c")."
";
echo session_encode();
?>
Output:
A: 1 - reg:
B: - reg:1
C: - reg:1
!b|!c|
//******** ***********************
session_get_cookie_params (PHP4 >= 4.0RC2)
array session_get_cookie_params (void);
Returns an array , records some information about the cookie of the current session.
There are:
"lifetime" - the lifetime of the cookie.
"path" - The path where the cookie is saved.
"domain" - The domain of the cookie.
//************************************
session_set_cookie_params (PHP4 >= 4.0b4)
void session_set_cookie_params (int lifetime [, string path][, string domain]])
Set some parameters of the session cookie, similar to the settings in php.ini, but the settings made by this function are only for the current script The file is valid.
//************************************
The function to be introduced below should be useful to everyone Very useful, are you interested in customizing a session that does not require cookies to be saved? This function can realize your idea.
Let me think about it, what are the benefits of not using cookies? At least, you don't have to worry about whether the client's cookie function is turned on, right?

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445154.htmlTechArticle Several supplementary functions about session Under PHP, there are many discussions about session. In fact, there are several more in PHP4 This function is something we usually don’t notice. Let me introduce them to you below...
Statement:
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