There is a php file to which data is sent via ajax. In the php file, the validation and processing of this data takes place, but after that I need to redirect to the page where I will need this data in the future. Where is the best place for me to store this data during a redirect?
|
2 answers
In the session they belong
- Start a session by calling
session_start() - Fill an array of
$_SESSION[] - Redirect
- Start a session by calling
session_start() - Read data from the
$_SESSION[] - If the data is no longer needed, remove it from the array.
hello.php
session_start(); $_SESSION['hello'] = 'World!'; header('Location: world.php'); world.php
session_start(); echo $_SESSION['hello']; unset($_SESSION['hello']); - And how do I properly remove the contents of the
$_SESSION[]using JS? You can, of course, create an invisible<div style="display: none">, stick data into it, parse it with JS and delete it, but you want to implement it all culturally, without crutches. - JamesJGoodwin - @JamesJGoodwin None. This is a server object. But nothing prevents it from displaying its contents on the page and using JS to parse the output - Anton Shchyrov
|
Your localStorage is fine for you. Variables of this object are stored at the browser level.
localStorage.setItem('ключ', 'значение'); localStorage.getItem('ключ'); localStorage.removeItem("Ключ"); localStorage.clear(); Everything is intuitive. And here is a good, easy article:
tproger.ru/articles/localstorage/
- will not work, there is no support by all browsers - Stanislav Belichenko
|
header('location'), then the redirect will work? Or is it better to wait for the script to finish working and redirect it via javascript viawindow.location? - JamesJGoodwin