Home  >  Article  >  Backend Development  >  How to achieve PHP redirection without losing data?

How to achieve PHP redirection without losing data?

Guanhui
GuanhuiOriginal
2020-06-15 17:49:442572browse

How to achieve PHP redirection without losing data?

#How does PHP redirection prevent data loss?

First get the data to be saved;

$data = [
	'username' => 'guanhuicoder',
	'redirect_url' => './index.php'
	'email' => 'guanhuicoder@code.com'
];

Then convert the data into a JSON string and store it in the Session;

$data = [
	'username' => 'guanhuicoder',
	'redirect_url' => './index.php'
	'email' => 'guanhuicoder@code.com'
];

$data = json_encode($data);

session_start();

$_SESSION['data'] = $data;

Then re- After orientation, take out and delete the data;

session_start();

$data = $_SESSION['data'];

unset($_SESSION['data']);

Finally, just decode the data into JSON.

$data = json_decode($data);

Recommended tutorial: "PHP""

The above is the detailed content of How to achieve PHP redirection without losing data?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn