0

I have some value for carry one page to another. For that I can use Ajax, Jquery or take them in form hidden field and post them by link. But I am trying it by session and session is good for hold the variable and can access just by declaring the variable. The issue is that, I have different item with price select by users so when they select the info should go on next page.

In case user want to switch his item then the session variable should switch the value but its not happening.

I tried this, not working

<?php
session_start();
if($_SERVER['REQUEST_URI']="/example/?page_id=150")
{

unset($_SESSION['price']);
//session_destroy();

}
?>

lets suppose I have three price in loop by $price, and I just store it in $_SESSION variable, If user select Price 1 then $_SESSION variable have Value of price1, Now IF he Again come to that page and change price1 to price2, then how $_SESSION store price2....

I can do this in other way but, Is it possible by session? Or any other way to do this?

Thanks..

1
  • 2
    You have used assign operator = instead of comparison operator == in if condition Commented Oct 23, 2013 at 9:25

1 Answer 1

1

Why are you unsetting the variable ? Instead you can replace the session variable with the current value.

Something like this

<?php
if($_SERVER['REQUEST_URI']=="/example/?page_id=150")
{
$val=$_GET['page_id'];
$_SESSION['id']=$val;
header("location:somepage.php");

somepage.php

<?php
echo $_SESSION['pid'];
2
  • will this work when user select another item by previous?...I just want to change session value by selecting item by users
    – Dinesh
    Commented Oct 23, 2013 at 9:31
  • how could this work, can you explain further more sir, lets suppose I have three price in loop by $price, and I just store it in $_SESSION variable, If user select Price 1 then $_SESSION variable have VAlue of price1, Now IF he Again come to that page and change price1 to price2, then how $_SESSION store price2....
    – Dinesh
    Commented Oct 23, 2013 at 9:47

Not the answer you're looking for? Browse other questions tagged or ask your own question.