dongyongju9560 2015-10-23 09:27
浏览 118

页面在登录时重定向到索引

I am creating a login system, my login and register script is working fine but when i started with page permission it did not work, it keeps on redirecting to the landing page

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();
    }
?>

I am being redirected as soon as I login,

  • 写回答

2条回答 默认 最新

  • douhaodang0403 2015-10-23 09:33
    关注

    Check session for this :-

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度