PHP重定向如何實現數據不丟失?
首先獲取要保存的數據;
$data = [ 'username' => 'zztuku', 'redirect_url' => './index.php' 'email' => 'zztuku@admin.com' ];
然后將數據轉為JSON字符串,并將其儲存在Session中;
$data = [ 'username' => 'zztuku', 'redirect_url' => './index.php' 'email' => 'zztuku@code.com' ]; $data = json_encode($data); session_start(); $_SESSION['data'] = $data;
接著在重定向后將數據取出并刪除;
session_start(); $data = $_SESSION['data']; unset($_SESSION['data']);
最后將數據進行JSON解碼即可。
$data = json_decode($data);