knowNothing Posted September 8, 2006 Share Posted September 8, 2006 Since session_register() is deprecated and I don't have access to turn register_globals on, and don't really want to anyway...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? Quote Link to comment https://forums.phpfreaks.com/topic/20140-_session-just-once/ Share on other sites More sharing options...
wildteen88 Posted September 8, 2006 Share Posted September 8, 2006 I would not recommend you to do that, as it is basically lazy programming. Yes when ever you want to access a session var you will need to use $_SESSION['var_name']. Why do you want to use $var_name to access your session variables?What you could do is extract the session variables from the session array using extract function, eg:[code=php:0]extract($_SESSION);[/code]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. Quote Link to comment https://forums.phpfreaks.com/topic/20140-_session-just-once/#findComment-88543 Share on other sites More sharing options...
knowNothing Posted September 8, 2006 Author Share Posted September 8, 2006 Maybe I don't even need this... here's my problem..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:[code]<a href="<? echo $PHP_SELF."?delete=1&idnum=".$_SESSION['idnum']; ?>">delete</a>[/code]it seems that the values for $delete and $idnum are not being fed back into $PHP_SELF Quote Link to comment https://forums.phpfreaks.com/topic/20140-_session-just-once/#findComment-88544 Share on other sites More sharing options...
wildteen88 Posted September 8, 2006 Share Posted September 8, 2006 Prehaps use this:[code=php:0]echo '<a href="' . $_SERVER['PHP_SELF'] . '?delete=1&idnum=' . $_SESSION['idnum'] . '">delete</a>';[/code]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 [url=http://uk2.php.net/manual/en/language.variables.predefined.php]here[/url] Quote Link to comment https://forums.phpfreaks.com/topic/20140-_session-just-once/#findComment-88546 Share on other sites More sharing options...
phporcaffeine Posted September 8, 2006 Share Posted September 8, 2006 I would always recommend reffering to $_SESSION['var_name'] becuase this way you know that your always getting your data, 'straight from the hourses mouth' and it hasn't had the chance to be accidentally overwritten. Since $_SESSION is such a unique syntax, it's not likely that you would overwrite a $_SESSION, and clients can't assign values to $_SESSION through global namespace. Quote Link to comment https://forums.phpfreaks.com/topic/20140-_session-just-once/#findComment-88558 Share on other sites More sharing options...
knowNothing Posted September 8, 2006 Author Share Posted September 8, 2006 cool.. ok in this case, if i pass the variable back to $_SERVER['DOCUMENT_ROOT'], i can simply reference it further using $_GET['delete'] without having to decare it as a session variable? Quote Link to comment https://forums.phpfreaks.com/topic/20140-_session-just-once/#findComment-88559 Share on other sites More sharing options...
wildteen88 Posted September 8, 2006 Share Posted September 8, 2006 That is correct, but it'll only work if your link is like this:mysite.com/page.php?delete=1Then 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. Quote Link to comment https://forums.phpfreaks.com/topic/20140-_session-just-once/#findComment-88572 Share on other sites More sharing options...
knowNothing Posted September 8, 2006 Author Share Posted September 8, 2006 Awsome. It worked. I just used:[code]<a href="<?php echo $_SERVER['PHP_SELF'] . '?delete=1&idnum=' . $idnum; ?>">delete</a>[/code]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. Quote Link to comment https://forums.phpfreaks.com/topic/20140-_session-just-once/#findComment-88575 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.