Save variable after refresh php

0

I have a code that saves the POST of a form in html in the $ ID variable, in case when this POST occurs the page changes due to this variable, then I would like to save it somehow so I did not lose it when dou refresh on the page, so the page does not change.

    
asked by anonymous 19.09.2017 / 17:37

1 answer

2

To solve your "problem" I recommend that you save this variable in a session, or even a cookie so that you can use it later.

If you wanted to save in a session, on the page that takes the data from $_POST , you could enter this code:

<?php
     session_start();//Colocar no inicio do código, se já não houver em alguma página que da include nessa
     //resto do código
     $id = $_POST['form'];
     $_SESSION['dados'] = $id;
     //resto do código
?>

Now to retrieve this data on any other page, you do the following:

<?php
     session_start();//Colocar no inicio do código, se já não houver em alguma página que da include nessa
     //resto do código
     $id = $_SESSION['dados'];
?>

Remembering that since it is SESSION , as soon as the browser is closed, that data will be "removed" from SESSION .

If you'd like to know about Cookies, this this page .

    
19.09.2017 / 17:47