会话变量在页面之间变化

时间:2011-06-05 19:02:44

标签: php session-variables

我遇到会话变量问题。当某人登录时,变量$_SESSION['id']将设置为数据库中的用户ID。但是,在一些处理和url更改后,此变量开始保存数据库中其他表的id。 此问题仅存在于生产网站上..不在我的本地主机上。 ..如何在所有网页上保持$_SESSION['id']的相同值?

session_start();
$query = "SELECT id, name, priviledge, approve FROM customers WHERE username='{$username}' AND password='{$password}' LIMIT 1";
$result = mysql_query($query,$connection);
report($result);
$returned = mysql_fetch_array($result);
$name = $returned['name'];
$id = $returned['id'];
$priviledge = $returned['priviledge'];
$approve = $returned['approve'];
if(isset($name)){       
    $_SESSION['id'] = $id;
//rest of the code
}

另一个档案:

        <?php 
            $query = "
                    SELECT name, address, phone, email
                    FROM customers
                    WHERE id = {$_SESSION['id']}
                    LIMIT 1;
                    ";
            $result = mysql_query($query);
            report($result);
            $row = mysql_fetch_assoc($result);
            $name = $row['name'];
            $addr = $row['address'];
            $ph = $row['phone'];
            $email = $row['email'];
            echo "<h5>Delivery Address</h5><p>&nbsp;</p>";
            echo "<span>{$name}<br />{$addr}<br />{$ph}<br />{$email}</span><p>&nbsp;</p>";
        ?>  

0 个答案:

没有答案