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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.