maliary Posted June 20, 2007 Share Posted June 20, 2007 Hi, I have this variable that is passed in the the $_GET, which I then assign it to a $_SESSION variable to ensure persistency, however every time i reload the page the $_SESSION variable gets lost. Hence unusable. $_SESSION ['very'] = $_GET['pery']; How can I ensure persistency beyond page reloads? Link to comment https://forums.phpfreaks.com/topic/56330-persistent-variables/ Share on other sites More sharing options...
papaface Posted June 20, 2007 Share Posted June 20, 2007 Try if (!$_SESSION['very']) { if ($_GET['pery']) { $_SESSION['very'] = $_GET['pery']; } } Link to comment https://forums.phpfreaks.com/topic/56330-persistent-variables/#findComment-278292 Share on other sites More sharing options...
Caesar Posted June 20, 2007 Share Posted June 20, 2007 In any page you want to use that session variable.... <?php session_start(); $very = $_SESSION ['very']; echo $very; //Should still output a value even on diferent pages; ?> Though you can also look into constants....doing this once....it has been defined and it's value won't change....so it depends on your script and logic in terms of what approach would be best. <?php define('VERY_DEFINED', $your_value); ?> Edit: But you must initiate the session (session_start()) before using the session variable in other pages. Link to comment https://forums.phpfreaks.com/topic/56330-persistent-variables/#findComment-278294 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.