簡體   English   中英

頁面正在登錄時重定向到索引

[英]page is redirecting to index on login

我正在創建一個登錄系統,我的登錄和注冊腳本運行正常,但是當我以頁面權限開始時,它不起作用,它將繼續重定向到登錄頁面

的index.php

<?php
    include_once("scripts/global.php");
    if( $logged == 1 ){
        header("Location:home.php");
        exit();
    }
?>


<!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Webplex</title>
        <link href="style1.css" rel="stylesheet" type="text/css">
    </head>
    <body>
        <div class="container center">
        <h1>Webplex</h1>
            <a href="register.php"><p>Register</p></a> | <a href="login.php"><p>Login</p> </a>
        </div>
    </body>
</html>

global.php

<?php 
session_start();
include("scripts/connect.php");

//check the session
if(isset($_SESSION['username'])){
    $session_username = $_SESSION['username'];
    $session_pass = $_SESSION['pass'];
    $session_id = $_SESSION['id'];

    //check member
    $query = mysql_query("SELECT*FROM members WHERE `id` = '$session_id' AND `password` = '$session_pass' LIMIT 1") or die("could not perform");
    $count_count = mysql_num_rows($query);
    if($count_count > 0){   
        //logged in stuff here
        $logged = 1;
    }else{
        $logged = 0;
        header("Location:logout.php");
        exit();
    }
}else if(isset($_COOKIE['id_cookie'])){
    $session_id = $_COOKIE['id_cookie'];
    $session_pass = $_COOKIE['pass_cookie'];

    //check member
    $query = mysql_query("SELECT*FROM members WHERE `id` = '$session_id AND `password` = '$session_pass' LIMIT 1")or die("could not perform");
    $count_count = mysql_num_rows($query);
    if($count_count > 0){
        while($row= mysql_fetch_array($query)){
            $session_username = $row['username'];
        }
        //create sessions
        $_SESSION['username'] = $session_username;
        $_SESSION['id'] = $session_id;
        $_SESSION['pass'] = $session_pass;

        //logged in stuff here
        $logged = 1;
    }else{
        header("Location:logout.php");
        exit();
    }
}else{
    //not logged in
    $logged = 0;
}
?>

home.php

<?php
    include_once("scripts/global.php");
    if( $logged == 0 ){
        header("Location:index.php");
        exit();
    }
?>

登錄后,我將被重定向,

檢查會話:-

session_start();
if(!isset($_SESSION['username'])){
header("Location:home.php");
exit();
}

我不知道您為什么在home.php中使用此代碼? $ logged == 1時 ,表示用戶已登錄系統,您再次重定向到home.php 它會循環嗎?

if( $logged == 1 ){
    header("Location:home.php");
    exit();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM