Jump to content

Persistent Variables


maliary

Recommended Posts

 

 

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.