$ _SESSION变量没有被替换?

时间:2013-07-13 22:50:36

标签: php session

第二位代码我需要替换当前的SESSION变量,而不是添加一个新变量。例如:$ _SESSION ['client'] = 254921,然后第二位的if语句应该用从我的$ _POST变量输入的新语句替换它。但相反,如果我将其更改为254922,$ _SESSION ['client']现在等于254921和254922.如何使254922替换254921?谢谢。

<?php
if(empty($_SESSION['client']) || empty($_SESSION['hash'])) {
        $secrets = mysql_fetch_array(mysql_query("SELECT * FROM `secrets`"));
        $_SESSION['client'] = rand(100000, 999999);
        $_SESSION['rand'] = rand(0, 10000)/100;
        $_SESSION['hash'] = hash('sha512', $_SESSION['rand'] . $_SESSION['client'] . $secrets['secret'] );


 }
 ?>

<?php
    if(!empty($_POST['client']) 
&& strlen($_POST['client']) == 6 
&& is_numeric($_POST['client'])) {

    $_SESSION['client'] = $_POST['client'];


}
?>

1 个答案:

答案 0 :(得分:0)

替换它:

$_SESSION['client'] = $_POST['client'];

由此:

unset($_SESSION['client']); // this will unset the variable $_SESSION['client']
$_SESSION['client'] = $_POST['client'];

我希望这会有所帮助。