Putting session value in a varrible in PHP
I want to store a value from a session in a variable to work on in the current script. However 开发者_开发问答when i run;
$from = $_SESSION['userid'];
echo '$from';
$from seems to be blank. When i run echo '$_SESSION['userid']'; it returns the correct value
Take out the quotes or change it to double quotes
echo $from;
When using single quotes variables aren't expanded. See the strings documentation for more on this.
You could either do:
echo $from;
or
echo "$from";
Assuming your id is an integer the code would be more secure this way:
$from = intval($_SESSION['userid']);
echo $from;
try
$from = $_SESSION['userid'];
echo $from;
echo $from;
You don't need quotes around variables to echo. IMHO it's bad practice.
精彩评论