2
2
20strannik082018-09-16 08:14:29
Sessions
20strannik08, 2018-09-16 08:14:29

How to correctly pass a variable through the session in php?

There is CMS Opencart. I drive in this value on a specific page (it will be displayed only on a specific page):

<?php 
     $my_var = "Тут какой-то текст"; 
     $_SESSION['my_var'] = $my_var; 
?>

There is a footer (It is displayed on any page), I put the following in it:
<?php 
     $my_var = ''; if ( isset($_SESSION['my_var']) ) { $my_var = $_SESSION['my_var']; unset( $_SESSION['my_var'] ); } echo $my_var; ?>

If there is no content in the session, then nothing is displayed, if there is, then it is displayed. When you enter the desired page, the desired content appears, and everything seems to work ... But for some reason, when you first visit the desired page, where the variable is written to the session, for some reason it is not displayed in the footer right away ... Only after a second update pages... It turns out that this data comes with a delay, although I expected it to arrive instantly when the page is first loaded... What did I do wrong? How to fix it? Or am I on the wrong path?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cybernoob, 2018-09-16
@cybernoob

The session must be started on each page to see its content

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question