Forum Moderators: coopster

Message Too Old, No Replies

Using a variable within a global variable name

         

radiator251

1:48 am on Oct 10, 2009 (gmt 0)

10+ Year Member



I'm trying to set a global variable specific to a user, so it will remain even if the session is ended. I tried using

$GLOBALS['TEMP_VARIABLE_'.$username] = "blah blah blah";

...but I'm getting an error saying "unexpected T_VARIABLE, expecting ']'", which suggests to me that I can't have another variable within the variable name. Is there another way of doing this?

Let me know if you need all the code, but I don't think it matters, it's just a syntax error. Thanks in advance.

TheMadScientist

2:03 am on Oct 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I can't reproduce the error...

<?php
$username="test";
$GLOBALS['TEMP_VARIABLE_'.$username] = "blah blah blah";
print_r($GLOBALS);

echo "<br /><br />".$GLOBALS['TEMP_VARIABLE_test'];
?>

Check the rest of your script.