本文主要是介绍PHP代码段摘要,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1:验证是否登陆。比如直接登陆用户界面的地址时验证用户是否登陆过。
<?php
//开启session
session_start();
if(!isset($_SESSION['id'])){ header("Location:../login.html"); exit();
}
isset()在php中用来检测变量是否设置,该函数返回的是布尔类型的值,即true/false。
2:实现关闭页面的时候,session的消除
<?php
session_unset();
session_destroy();
?>
The session_unset() function frees all session variables currently registered.
session_destroy() destroys all of the data associated with the current session. It does not unset any of the global variables associated with the session, or unset the session cookie. To use the session variables again, session_start() has to be called.
In order to kill the session altogether, the session ID must also be unset.
代码段的位置:直接写在主页面代码的下面就好了
这篇关于PHP代码段摘要的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!