PHP根据另一个会话值更新会话值

时间:2017-10-31 11:00:28

标签: php session

我正在尝试使用以下代码更新基于另一个会话值($_SESSION['adtitle'])的会话值($_SESSION['amount'])。它适用于第一次页面加载,但之后它没有尽管我的主会话$_SESSION['amount']正在更新

,但相应地更新了会话
<?php
 session_start();
 if (isset($_SESSION['amount'])) {

 if($_SESSION['amount']=2)
 $_SESSION['adtitle']="Premium Listings for $2";

 else if ($_SESSION['amount']=4)
 {$_SESSION['adtitle']="Premium Blogs for $4";}

 } else {
 $_SESSION['adtitle']="Pls select your purchase type again!!";
 }
 header('Location: '. $_SERVER['HTTP_REFERER'] . '');
?>

1 个答案:

答案 0 :(得分:0)

在比较中缺少=。我已经解决了这个问题

<?php
 session_start();
 if (isset($_SESSION['amount'])) {

 if($_SESSION['amount']==2)
 $_SESSION['adtitle']="Premium Listings for $2";

 else if ($_SESSION['amount']==4)
 {$_SESSION['adtitle']="Premium Blogs for $4";}

 } else {
 $_SESSION['adtitle']="Pls select your purchase type again!!";
 }
 header('Location: '. $_SERVER['HTTP_REFERER'] . '');
?>