在本文中,我们将为您详细介绍PHP–按Back按钮后的Session_Destroy的相关知识,并且为您解答关于php按键的疑问,此外,我们还会提供一些关于darkestofdaysphp中sessi
在本文中,我们将为您详细介绍PHP – 按Back按钮后的Session_Destroy的相关知识,并且为您解答关于php按键的疑问,此外,我们还会提供一些关于darkest of days php中session_unset与session_destroy的区别分析、PHP session destroyed / lost after header、php session_decode函数只要解码的功能,不想存入$_SESSION里头、PHP SESSION_destroy 和 SESSION_unset的有用信息。
本文目录一览:- PHP – 按Back按钮后的Session_Destroy(php按键)
- darkest of days php中session_unset与session_destroy的区别分析
- PHP session destroyed / lost after header
- php session_decode函数只要解码的功能,不想存入$_SESSION里头
- PHP SESSION_destroy 和 SESSION_unset
PHP – 按Back按钮后的Session_Destroy(php按键)
我有一个名为login.PHP的登录页面(不包含HTML代码).当用户正确输入他的凭证时,他被重定向到特定页面;我们将为此示例说test.PHP.该页面上唯一的链接注销当前会话,并将用户返回到index.html.
我的问题是,如果用户按下后退按钮,它将返回login.PHP,你会得到一个空白页面.如果您离开该空白页面,则无法返回test.PHP,因此无法注销该会话.
我最初的想法是使用Javascript禁用后退按钮导航.最终我发现这不起作用,因为如果用户找到了一种离开该页面而没有注销的方法,那么它们将被卡在该会话中并且login.PHP将是空白的.
那么如果按下后退按钮,有没有办法结束当前会话?或者如果重新加载login.PHP?我不太熟悉PHP,所以非常感谢详细解释.
以下是登录页面的代码:
<?PHP /** * The idea of this application is to secure any page with one link. I kNow some of the professionals * will agree with me considering the way it has been done,usually you wouldnt put any other information such as * HTML/CSS with a class file but in this case its unavoidable. This is to make it easier for the non techys to use. * @author John Crossley <john@suburbanarctic.com> * @version Version 2 **/ // Turn off error reporting. error_reporting(0); # Start a new session,regenerate a session id if needed. session_start(); if (!isset($_SESSION['INIT'])) { session_regenerate_id(); $_SESSION['INIT'] = TRUE; } class JC_fsl { public static $_init; protected $_users = array(); # Script configuration protected static $_script_name; protected static $_admin_email; protected static $_admin_name; private static $_version = '{Version 2.0.1}'; protected function __construct() { if (!isset($_SESSION['LOGIN_ATTEMPTS'])) $_SESSION['LOGIN_ATTEMPTS'] = 0; // Default user admin added. $this->_users = array( array( 'USERNAME' => 'admin','PASSWORD' => 'master13','EMAIL' => 'seth@procstaff.com','LOCATION' => 'master.PHP') ); } public function __toString() { return 'SCRIPT NAME :: ' . self::$_script_name . "<br />" . ' ADMIN EMAIL :: ' . self::$_admin_email . "<br />" . ' ADMIN NAME :: ' . self::$_admin_name . "<br />" . ' FSL VERSION :: ' . self::$_version; } /** * This method allows you to peek inside the users list,so you can view their information. **/ public function peek() { var_dump($this->_users); } protected function ready_array($username,$password,$email,$location = 'index.html',$access = false) { return array('USERNAME' => $username,'PASSWORD' => $password,'EMAIL' => $email,'LOCATION' => $location); } public function add($username,$location = 'index.html') { $add = $this->ready_array($username,$location); $this->_users[] = $add; } public static function logout() { if (isset($_SESSION['LOGGED_IN'])) { if (session_destroy()) header('Location: index.html'); } } /** * This method increments or returns login attempts. * @param <bool> true to increment by 1 and false to return. */ public static function attempts($add = false) { if ($add === true) $_SESSION['LOGIN_ATTEMPTS'] += 1; else return $_SESSION['LOGIN_ATTEMPTS']; } public function site_name() { return self::$_script_name; } public function validate($un,$pw) { # Check all of the arrays for the user for ($i=0;$i<count($this->_users);$i++) { if (array_key_exists('USERNAME',$this->_users[$i])) { if ($this->_users[$i]['USERNAME'] == $un) { # We have found the user check to see if there password matches also. $info = $this->_users[$i]; if ($info['USERNAME'] == $un && $info['PASSWORD'] == $pw) { # We have a match redirect the user. $_SESSION['LOGGED_IN'] = TRUE; $_SESSION['LOGIN_ATTEMPTS'] = 0; $_SESSION['USERNAME'] = $info['USERNAME']; $_SESSION['EMAIL'] = $info['EMAIL']; header('Location: ' . $info['LOCATION']); return; } } } } echo '<h2 class=\'error\'>Incorrect username and or password,try again!</h2>'; self::attempts(true); } /** * Forgot password? not a problem call this method with the correct username * and the user will be sent a password reminder. Please note that not of these passwords * are hashed meaning this is not a good idea to store personal information behind this script! * @param <string> The users email address. * @return <bool> Returns true upon success. */ public function forgot($email) { for ($i=0;$i<count($this->_users);$i++) { if (array_key_exists('EMAIL',$this->_users[$i])) { if ($this->_users[$i]['EMAIL'] == $email) $info = $this->_users[$i]; } else return false; } if (isset($info) && is_array($info)) { # Send the user their password $to = $info['EMAIL']; $subject = 'You recently forgot your password | ' . self::$_script_name; $message = 'Hi ' . $info['USERNAME'] . ',' . "\n\n"; $message .= 'You recently requested your password for ' . self::$_script_name . ' if you didn\'t not to worry just ignore this '; $message .= 'email. Anyway you can find your email below,should you require anymore assistance then please contact us '; $message .= 'at ' . self::$_admin_email . ".\n\n"; $message .= 'Username: ' . $info['USERNAME'] . "\n"; $message .= 'Password: ' . $info['PASSWORD']; $message .= "\n\n" . 'Best Regards,' . "\n" . self::$_admin_name; $headers = 'From: ' . self::$_admin_email . "\r\n" . 'Reply-To: ' . self::$_admin_email . "\r\n" . 'X-Mailer: PHP/' . PHPversion(); # Uncomment for final version if (mail($to,$subject,$message,$headers)) return true; } } /** * The secure method,simply call this to lock any page down it's as simple as that. * @param <string> Name of the script EG: John's Script * @param <string> Email of the administrator EG: john@suburbanarctic.com * @param <string> Admin name EG: John Crossley * @return <object> Returns an instanciated object of this class. */ public static function secure($s_name = '',$a_email = '',$a_name = '') { self::$_script_name = $s_name; self::$_admin_email = $a_email; self::$_admin_name = $a_name; if (!self::$_init instanceof JC_fsl) { self::$_init = new JC_fsl(); } return self::$_init; } } # You may edit me $secure = JC_fsl::secure(); ########################################################################## ########################## YOUR EDITING BLOCK ########################### $secure->add('mbhaynes','mbhaynes13','seth@procstaff.com','mbhaynes.PHP'); $secure->add('emory','emory13','emory.PHP'); $secure->add('ehg','ehg13','redirect.html'); $secure->add('dhgriffin','dhgriffin13','dhgriffin.PHP'); $secure->add('neo','neo13','neo.PHP'); $secure->add('first','first13','first.PHP'); $secure->add('test','test','test.PHP'); ########################################################################## ########################################################################## ############ FORM PROCESSING ############ if (isset($_POST['username']) && isset($_POST['password'])) { $secure->validate($_POST['username'],$_POST['password']); } if (isset($_GET['logout'])) $secure->logout(); if (isset($_POST['forgot_password_button']) && isset($_POST['email'])) { // We need to send the user their password. if ($secure->forgot($_POST['email'])) { echo '<h2 class=\'success\'>Your password has been sent to your email address!</h2>'; } else { echo '<h2 class=\'error\'>I\'m sorry but that email address has no record on this site.</h2>'; } } ?> <?PHP if(!isset($_SESSION['LOGGED_IN'])): ?> <style type='text/css'> #fslv2-main{ font-family:HelveticaNeue-Light,"Helvetica Neue Light","Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;font-weight:300;font-size:14px;line-height:1.6; margin-left:auto; margin-right:auto; width: 300px; padding: 10px 10px 10px 10px; } fieldset { border: none; margin: 0; padding: 0;} .fslv2 .input { border: 1px solid #b9b9b9; padding: 5px; width: 225px; outline: none; font-size: 13px; } .fslv2 label { float: left; width: 72px; line-height: 28px; } h3 { font-weight: normal; } a { color: #4a6a81; text-decoration: none; } a:hover { color: #4a6a81; text-decoration: underline; } .button { border: 1px solid #233d4f; border-bottom: 1px solid #233d4f; background-color: #4a6a81; border-radius: 2px; padding: 6px 5px; color: #ffffff; text-shadow: 0 1px rgba(0,0.1); margin-left:auto; margin-right:auto; top: 5px; width: 100px; min-width: 100px; cursor: pointer; font-size: 13px; Box-shadow: rgba(0,0.2); -webkit-Box-shadow: rgba(0,0.2); -moz-Box-shadow: rgba(0,0.2); } .input:focus { -moz-Box-shadow: inset 0 0 3px #bbb; -webkit-Box-shadow: inset 0 0 3px #bbb; Box-shadow: inner 0 0 3px #bbb; } .fsl p.la { text-align: center; } .success { margin: 2em auto 1em auto; border: 1px solid #337f09; padding: 5px; background-color: #dd4b39; width: 400px; text-align: center; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; font-weight: normal; font-family:HelveticaNeue-Light,sans-serif;font-weight:300;font-size:14px;line-height:1.6; } .error { margin: 2em auto 1em auto; border: 1px solid #233d4f; padding: 5px; background-color: #8bafc5; width: 400px; text-align: center; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; font-weight: normal; font-family:HelveticaNeue-Light,sans-serif;font-weight:300;font-size:14px;line-height:1.6; } </style> <div id="fslv2-main"> <?PHP if($secure->attempts() > 5): ?> <!-- Show the login form --> <p>Too many Failed attempts,please try again later.</p> <?PHP elseif(isset($_GET['forgot_password'])): ?> <fieldset> <form method="post" action="#"> <p> <label for='email'>Email: </label> <input type='text' name='email'/> </p> <p><input type='submit' name='forgot_password_button'value='Send!' /></p> </form> </fieldset> <small><a href="index.html">Cancel</a></small> <?PHP else: ?> <fieldset> <legend><?PHP echo $secure->site_name(); ?></legend> <form method="post" action="#"> <p> <label for='username'>Username: </label> <input type='text' name='username'/> </p> <p> <label for='password'>Password: </label> <input type='password' name='password'/> </p> <p><input type='submit' name='login'value='Login' /></p> </form> </fieldset> <?PHP endif; ?> </div><!-- #fslv2-main --> <?PHP exit(); endif; ?>
解决方法
编辑:
它不会影响具有单独页面的用户,因为整个登录表单将在登录后由该用户内容更改.
试试这个:
if(isset($_SESSION['LOGGED_IN'])){ //User is logged-In check for existence of its name file,$user = $_SESSION["LOGGED_IN"]."PHP"; If(file_exists($user)){ //User's named file exists Now include it. include("yourfolder/$user"); }else{ //He was loggedIn in but file wasn't found... echo"Sorry nothing for you :P"; } }else{ //Show the logIn form }
darkest of days php中session_unset与session_destroy的区别分析
session_unset()
释放当前在内存中已经创建的所有$_SESSION变量,但不删除session文件以及不释放对应的session
id
session_destroy()
删除当前用户对应的session文件以及释放session
id,内存中的$_SESSION变量内容依然保留
因此,释放用户的session所有资源,需要顺序执行如下代码:
复制代码 代码如下:
$_SESSION[''user''] = ''lowell'';
session_unset();
session_destroy();
?>
以上就介绍了darkest of days php中session_unset与session_destroy的区别分析,包括了darkest of days方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
PHP session destroyed / lost after header
在header重定向后,注册的session居然消失了?! 找到解决办法: After the Header redirect you need to exit the PHP script: header(Location: /); exit(); 参考:http://stackoverflow.com/questions/2037316/php-session-destroyed-lost-after-header
在header重定向后,注册的session居然消失了?!
找到解决办法:
After the Header redirect you need to exit the PHP script:
header("Location: /"); exit();
参考:http://stackoverflow.com/questions/2037316/php-session-destroyed-lost-after-header
php session_decode函数只要解码的功能,不想存入$_SESSION里头
php session_decode函数只要解码的功能,不想存入$_session里头
回复内容:
php session_decode函数只要解码的功能,不想存入$_session里头
PHP SESSION_destroy 和 SESSION_unset
如何解决PHP SESSION_destroy 和 SESSION_unset?
ses.PHP
<?PHP
session_start();
$_SESSION["favclor"] = "green";
$_SESSION["favanimal"] = "cat";
?>
<!DOCTYPE html>
<html>
<body>
<?PHP
echo "Sesion variables set <br>";
echo "Favourite color is ".$_SESSION["favclor"]."<br> ";
echo "favourite animal is ".$_SESSION["favanimal"];
?>
</body>
</html>
销毁.PHP
<?PHP
session_start();
session_destroy();
echo "session is destroyed";
?>
当我运行代码时,session_destroy()
不起作用。 session_destroy()
销毁创建的会话后,我仍然可以看到创建的会话变量及其值。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
关于PHP – 按Back按钮后的Session_Destroy和php按键的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于darkest of days php中session_unset与session_destroy的区别分析、PHP session destroyed / lost after header、php session_decode函数只要解码的功能,不想存入$_SESSION里头、PHP SESSION_destroy 和 SESSION_unset等相关知识的信息别忘了在本站进行查找喔。
本文标签: