单击链接时注销

时间:2015-04-22 19:25:03

标签: php login logout

我的网站登录代码出现问题,系统允许用户登录并成功注销,但是当用户登录并点击其他网页链接时,系统会将其注销。我希望他们保持登录所有页面,直到用户单击自己注销。

loginform.php:

    <div id="contact">
       <form id="form" action="<?php $_SERVER['PHP_SELF'];?>" method="post">
           Username: <input type="text" name="liusername" id="liusername">
           Password: <input type="password" name="lipassword" id="lipassword">
           <input type='submit' value='Login'   name="lisubmit">
       </form>
    </div>

heading.php上的PHP代码:

    <?php

if ($_SESSION['loggedin'] === true){

echo "You have signed in - <a href='loggedout.php'>Click here to log out</a>";

 } ELSE {
INCLUDE 'loginform.php';
 }

 if (isset($_POST['lisubmit'])){

$query = "SELECT user_id, user_password, user_username FROM users WHERE
        user_username = '".$_POST['liusername']."'";
        $result = mysql_query($query) or die (mysql_error());
        $row = mysql_fetch_array($result);

        if ($row['user_password'] === $_POST['lipassword'] && $row['user_username'] === $_POST['liusername']){

            $_SESSION['loggedin'] = true;
            $_SESSION['id'] = $row['user_id'];
        }else{
            $_SESSION['loggedin'] = false;
            $_SESSION['id'] = 0;
            INCLUDE 'loginform.php';

        }
}

   ?>

的index.php:

    if(empty($_SESSION['loggedin'])){$_SESSION['loggedin'] = false;
    }

Loggedout.php:

    <?php 

    session_start();

    $_SESSION= ARRAY();

    SESSION_DESTROY();

    HEADER('location: index.php');

    ?>

0 个答案:

没有答案