$_SESSION just once?
Posted 08 September 2006 - 05:02 PM
If I declare a variable using $_SESSION, will I have to eternally refer to it as $_SESSION["variable_here"] wherever I use it in the code or does using $_SESSION once, in effect, make it permanently global, and I can use $variable_here throughout the code?
Posted 08 September 2006 - 05:27 PM
What you could do is extract the session variables from the session array using extract function, eg:
extract($_SESSION);Then you can use $var_name to access your var_name session. However this to me is lazy programming.
However you'll still need to use $_SESSION['var_name'] to create the var_name session and to change the value of the session. You can only use extract when you want to retrieve the session vars.
Posted 08 September 2006 - 05:29 PM
I'm making a news admin script and I'm trying to pass variables back into $PHP_SELF so that I can delete and edit news posts, but when I use something like:
<a href="<? echo $PHP_SELF."?delete=1&idnum=".$_SESSION['idnum']; ?>">delete</a>
it seems that the values for $delete and $idnum are not being fed back into $PHP_SELF
Posted 08 September 2006 - 05:31 PM
echo '<a href="' . $_SERVER['PHP_SELF'] . '?delete=1&idnum=' . $_SESSION['idnum'] . '">delete</a>';
To get the delete and idnum variables fromo the URL you use $_GET['delete'] and $_GET['idnum'] instead of $delete and $idnum.
You might want to look into the superglobal arrays over at php.net. You use the supergloabl arrays when register_global is off (and when its on).
The superglobals are _POST, _GET, _COOKIE, _SESSION, _SERVER etc. You can learn more about supergloabls here
Posted 08 September 2006 - 05:49 PM
President & Founder, MyCodeTree
email@example.com | http://mycodetree.com
Posted 08 September 2006 - 05:50 PM
Posted 08 September 2006 - 06:07 PM
Then you access the delete variable using $_GET['delete']
However if you want to use the get variable in another page, that doesnt send the delete variable through the url you'll need to use a session or a cookie to store the delete variable.
Posted 08 September 2006 - 06:12 PM
<a href="<?php echo $_SERVER['PHP_SELF'] . '?delete=1&idnum=' . $idnum; ?>">delete</a>
and then once the variable was passed back into the document, I referenced it using $_GET['idnum'] and $_GET['delete'] and the function performed properly (removed the correct news entry). I have no need to use them in another document, so I wont need to use $_SESSION.
Thanks for all your help guys.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users