Basically what the title says. I know how to make a normal variable into a session variable ($_SESSION['var']), but not when it contains another var
This is my code:
<?php
session_start();
$_SESSION["uname"] = "Tyler";
if (isset($_SESSION["coins{$uname}"]))
{
echo "$_SESSION["uname"] : $_SESSION["coins{$uname}"]";
}
elseif ($_SESSION["uname"] == "LOut")
{
$_SESSION["coins{$uname}"] = "0";
echo "Log In";
}
else
{
$_SESSION["coins{$uname}"] = 500;
echo "$_SESSION["uname"] : $_SESSION["coins{$uname}"]";
}
?>
I’ve tried the following:
$_SESSION['{coins.$uname}']
$_SESSION['coins.$uname']
$_SESSION['coins.$_SESSION['uname']']
And I don’t remember if I’ve tried anything else.
You say that it’s not working, but you haven’t specified if setting it or echoing it is the problem: Based on your original, unedited question, there are two problems:
Setting the session variable
This should work:
If you can’t get it to work, try breaking it down into a couple of steps.
Now test it.
Outputting the session variable
echo $_SESSION["coins{$uname}"];orecho $_SESSION[$tempname];Edit
There is a syntax error in your code:
You are closing your starting quote (“) by mistake when you try to open quotes for [“uname”]. Try: