PHP - 重定向循环错误

时间:2015-02-05 23:19:13

标签: php

每次我访问index.php页面时,我都会在Google Chrome上收到以下错误:

  

此网页有重定向循环

哦我的phpmyadmin数据库,如果account_type中的文字是'取消激活',我就这样做了,这样用户就会自动重定向到logout.php(这是在functions.php页面中)

如果它“活跃”,则没有任何反应。

我的index.php代码:

<?php include_once 'connect.php';?>
<?php include_once 'functions.php';?>

<!doctype html>
<html lang="en" class="home-page">
    <head>
    </head>
    <body>

      <ul class="linklist-admin">

        <?php
        if (loggedin()){ ?>
        <li><a href="profile">My Profile</a></li>

    <?php } else { ?>

            <li><a href="login.php">Sign In</a></li>

    <?php } ?>
      </ul>

    </body>
</html>

我的functions.php代码:

   <?php

session_start();

function loggedin(){
if (isset($_SESSION['user_id']) && !empty($_SESSION['user_id'])){
    return true;
        } else {
            return false;
    }
    }

if(loggedin()){
$my_id = $_SESSION['user_id'];
$user_query = mysql_query("SELECT username, account_type FROM users WHERE id='$my_id'");
$run_user = mysql_fetch_array($user_query);
$username = $run_user['username'];
$account_type = $run_user['account_type'];

$query_level = mysql_query("SELECT name FROM user_level WHERE id='$user_level'");
$run_level = mysql_fetch_array($query_level);
$level_name = $run_level['name'];

$d = 'deactivate';
$a = 'active';

}



if($account_type == $d) { //logs you out if your account is deactivated.
header('location: logout.php');
}


?>

我的logout.php代码:

 <?php

include 'connect.php';
include 'functions.php';

session_destroy();

header('location: index.php');

1 个答案:

答案 0 :(得分:0)

if($account_type == $d) {

 //do stuff here 

}

我认为这就是你想要的。