dongnuo4594 2015-04-22 19:25
浏览 10

单击链接时注销

I'm having trouble with my log in code for my website, the system allows for a user to log in and log out successfully however when the user is logged in and clicks on another webpage link, its signs them out. I want them to stay logged in on all pages until the user clicks log out themselves.

The 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>

PHP code on heading.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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数