PHP重定向如何实现数据不丢失?
首先获取要保存的数据;$data = [
'username' => 'guanhuicoder',
'redirect_url' => './index.php'
'email' => 'guanhuicoder@code.com'
];
然后将数据转为JSON字符串,并将其储存在Session中;$data = [
'username' => 'guanhuicoder',
'redirect_url' => './index.php'
'email' => 'guanhuicoder@code.com'
];
$data = json_encode($data);
session_start();
$_SESSION['data'] = $data;
接着在重定向后将数据取出并删除;session_start();
$data = $_SESSION['data'];
unset($_SESSION['data']);
最后将数据进行JSON解码即可。$data = json_decode($data);
推荐教程:《PHP》”