[英]How to assign a session value to a variable
I have a session which I need to assign to a variable to be used on Stored Procedure. 我有一个会话,需要将其分配给要在存储过程中使用的变量。 But cant seem to get the variable being affected on it
但是似乎无法使变量受到影响
I have already tried the following, but nothing 我已经尝试了以下方法,但是什么也没有
1) 1)
ob_start();
echo $_SESSION['User'];
$userV = ob_get_contents();
ob_end_clean();
2) 2)
$userV = $_SESSION['User'];
3) 3)
$userV= echo $_SESSION['User']; //fails as echo, used print instead
4) 4)
$userV= print $_SESSION['User'];
But when I use a know value like below it works 但是当我使用如下所示的已知值时,它起作用
$userV= 41;
The intended Procedure as follows: 预期的程序如下:
$sql="CALL sp_getUser('$userV')";
The second one is the correct one: $userV = $_SESSION['User'];
第二个是正确的:
$userV = $_SESSION['User'];
. 。 If
$userV
does not hold the expected value after this assignment, two things can be the reason: You haven't initialized the session ( session_start()
) or the you haven't set the $_SESSION["User"]
(somewhere in another script you should have something like $_SESSION["User"]=41;
. 如果
$userV
在执行此赋值操作后未保存期望值,则可能是由于以下两个原因:您尚未初始化会话( session_start()
)或尚未设置$_SESSION["User"]
(另一个脚本应该具有类似$_SESSION["User"]=41;
脚本。
You can test what is in the $_SESSION-variable presently by print_r($_SESSION);
您可以通过
print_r($_SESSION);
测试当前$ _SESSION变量中的内容print_r($_SESSION);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.