简体   繁体   English

设置不同值的会话

[英]unset session for different value

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. 为此,我可以使用Ajax,Jquery或以隐藏字段的形式使用它们并通过链接发布它们。 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.... 假设我有3个以$ price循环的价格,然后将其存储在$ _SESSION变量中,如果用户选择Price 1,则$ _SESSION变量的价格为price1,现在,如果他再次来到该页面并将price1更改为price2,然后$ _SESSION如何存储价格...。

I can do this in other way but, Is it possible by session? 我可以用其他方式执行此操作,但是,按会话可以吗? Or any other way to do this? 或任何其他方式做到这一点?

Thanks.. 谢谢..

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 somepage.php

<?php
echo $_SESSION['pid'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM