PHP   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了取消全局会话变量作为注销按钮大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

嘿Stackoverflow用户,

由于我能够在遇到问题之前获得一些惊人的帮助,所以我被困了很长时间,以至于我不记得我以为会遇到这个问题.

使用可以验证用户身份并终止会话的登录系统,但当前它无法识别分配给该会话的变量.单击注销按钮后,一切似乎都可以正常工作,但是当通过在地址栏中键入它来直接连接到成员页面时,它将加载页面,而不是重定向登录页面.

会员.PHP

<?PHP
session_start();
if (!isset($_SESSION['username'])) {
header('LOCATIOn:login.PHP');
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<Meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>The Animator BETA</title>
<style>
//CSS Has been removed as it's lengthy and unrelated to the issue.
</style>
<!--[if lt IE 9]>

        <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>

    <![endif]-->        

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>

<script>

          $(document).ready(function(){

                $('#login-trigger').click(function(){

                    $(this).next('#login-content').slideToggle();

                    $(this).toggleClass('active');                  



                    if ($(this).hasClass('active')) $(this).find('span').html('&#x25B2;')

                        else $(this).find('span').html('&#x25Bc;')

                    })

          });

    </script>
</head>
<body>
<header class="cf">

<nav style="text-align:center"><a href="logout.PHP">logout</a></nav>

</header>

<h1 style="text-align:center"> The Animator - BETA</h1>
<hr />
<div id="nav" style="text-align:center">
<ul style="text-align:center">

<li><a href= "#" ><strong>Home</strong></a></li>
<strong><li><a href= "induStrial.html" >InduStrial</a></li>
<li><a href= "educational.html" >Education</a></li>
<li><a href= "independent.html"  >Independent</a></li>
<li><a href= "emergent.html"  >Emergent</a></li>
<li><a href= "team.html" >Team</a></li>
<li><a href= "project.html"  >Project</a></li>
<li><a href= "budget.html" >Budget</a></li>
<li><a href= "profile.html" >Profile</a></li></strong>

</ul>
</div>
<hr />
<div style="padding-left:19%"><input type="text" value="search" />
<input type="button" value="Search!" name="search"/>
</div>
<div>&nbsp;</div>
<div align="center">
<div><img src="logo.png" width="407" height="345" alt="logo" usemap="sectors" /></div>

</div>
</div>
<map name="sectors">
  <area shape="rect" coords="72,40,194,165" alt="InduStrial" href="induStrial.html">
  <area shape="rect" coords="210,38,328,162" alt="Emergent" href="emergent.html">
  <area shape="rect" coords="208,178,331,296" alt="Independent" href="independent.html">
    <area shape="rect" coords="71,177,194,295" alt="Educational" href="educational.html">

</map>
<div>&nbsp;</div>
<div style="text-align:right"></div>
<div>&nbsp;</div>   
<div id="footer"> <hr />
  <p><strong><u><a href="about.html">About The Animator</a> | <a href="contact.html">Contact</a> | <a href="privacy.html">Privacy Policy</a> | <a href="faq.html">FAQ</a></u></strong><u></u></p>
</div>
</body>
</html>

登录页面

<?PHP

error_reporTing(E_ALL);
ini_set('display_errors',"On");

include ('database_connection.PHP');
if (isset($_POST['formsubmitted'])) {
    // Initialize a session:
session_start();
    $error = array();//this aaray will store all error messages


    if (empty($_POST['e-mail'])) {//if the email supplied is empty 
        $error[] = 'You forgot to enter  your Email ';
    } else {


        if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['e-mail'])) {

            $Email = $_POST['e-mail'];
        } else {
             $error[] = 'Your Email Address is invalid  ';
        }


    }


    if (empty($_POST['password'])) {
        $error[] = 'Please Enter Your password ';
    } else {
        $password = $_POST['password'];
    }


       if (empty($error))//if the array is empty , it means no error found
    { 



        $query_check_credentials = "@R_197_1171@ccount WHERE (email='$Email' AND passwords='$password')";



        $result_check_credentials = MysqLi_query($dbc, $query_check_credentials);
        if(!$result_check_credentials){//If the QUery Failed 
            echo 'Query Failed ';
        }

        if (@MysqLi_num_rows($result_check_credentials) == 1)//if Query is successfull 
        { // A match was made.





            $_SESSION = MysqLi_fetch_array($result_check_credentials, MysqLI_ASSOC);//Assign the result of this query to SESSION Global Variable

            $_SESSION['email'] = $Email; 

           session_start("username");

            header("LOCATIOn: members.PHP");



        }else
        { 

            $msg_error= 'Either Your Account is inactive or Email address /password is Incorrect';
        }

    }  else {



echo '<div class="errormsgBox"> <ol>';
        foreach ($error as $key => $values) {

            echo '  <li>'.$values.'</li>';



        }
        echo '</ol></div>';

    }


    if(isset($msg_error)){

        echo '<div class="warning">'.$msg_error.' </div>';
    }
    /// var_dump($error);
    MysqLi_close($dbc);

} // End of the main Submit conditional.



?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<Meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login Form</title>





<style type="text/css">
body {
    font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
    font-size:12px;
}
.registration_form {
    margin:0 auto;
    width:500px;
    padding:14px;
}
label {
    width: 10em;
    float: left;
    margin-right: 0.5em;
    display: block
}
.submit {
    float:right;
}
fieldset {
    BACkground:#EBF4FB none repeat scroll 0 0;
    border:2px solid #B7DDF2;
    width: 500px;
}
legend {
    color: #fff;
    BACkground: #80D3E2;
    border: 1px solid #781351;
    padding: 2px 6px
}
.elements {
    padding:10px;
}
p {
    border-bottom:1px solid #B7DDF2;
    color:#666666;
    font-size:11px;
    margin-bottom:20px;
    padding-bottom:10px;
}
a{
    color:#0099FF;
font-weight:bold;
}

/* Box Style */


 .success, .warning, .errormsgBox, .validation {
    border: 1px solid;
    margin: 0 auto;
    padding:10px 5px 10px 60px;
    BACkground-repeat: no-repeat;
    BACkground-position: 10px center;
     font-weight:bold;
     width:450px;

}

.success {

    color: #4F8A10;
    BACkground-color: #DFF2BF;
    BACkground-image:url('images/success.png');
}
.warning {

    color: #9F6000;
    BACkground-color: #FEEFB3;
    BACkground-image: url('images/warning.png');
}
.errormsgBox {

    color: #D8000c;
    BACkground-color: #FFBABA;
    BACkground-image: url('images/error.png');

}
.validation {

    color: #D63301;
    BACkground-color: #FFCCBA;
    BACkground-image: url('images/error.png');
}



</style>

</head>
<body>


<form action="login.PHP" method="post" class="registration_form">
  <fieldset>
    <legend>Login Form  </legend>

    <p>Enter Your username and password Below  </p>

    <div class="elements">
      <label for="name">Email :</label>
      <input type="text" id="e-mail" name="e-mail" size="25" />
    </div>

    <div class="elements">
      <label for="password">password:</label>
      <input type="password" id="password" name="password" size="25" />
    </div>
    <div class="submit">
     <input type="hidden" name="formsubmitted" value="TRUE" />
      <input type="submit" value="Login" />
    </div>
  </fieldset>
</form>
<button onclick="window.LOCATIOn='theanimator.html';">Go BACk!</button>
</body>
</html>

登出

<?PHP
unset($_SESSION['email']);
header('LOCATIOn: login.PHP');
exit;
?>

解决方法:

您的登出页面必须是这样的

<?PHP

//start the session
session_start();
//this will destroy the session that is started
session_destroy();
header('LOCATIOn: login.PHP');
exit;
?>

问题是,您没有销毁会话,因此当您返回页面时,该会话存在.

另外,您正在查看$_SESSION [‘username’],但未设置$_SESSION [’email’],这将永远无法进行.

大佬总结

以上是大佬教程为你收集整理的取消全局会话变量作为注销按钮全部内容,希望文章能够帮你解决取消全局会话变量作为注销按钮所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: