php会话无法正常工作!知道为什么它将null值传递给第二页?
file1.php:
<?php
session_start();
$_SESSION['lat']=$_POST['lat'];
$_SESSION['lng']=$_POST['lng'];
session_write_close();
header('Location: http://sample.com/e_health/searchambulance.php');
?>
file2:
<?php
session_start();
$lat= $_SESSION['lat'];
$lng=$_SESSION['lng'];
echo $lat;
echo $lng;
?>
答案 0 :(得分:0)
你可能想要测试(至少)两件事:
a)使用这两个POST参数调用file1吗?
b)会话ID的传播是否有效? (对于两个&#34;文件&#34;输出session_id = xyz必须相同,否则第二个请求不会紧接第一个请求的会话)
文件1:
<?php
if ( !isset($_POST['lat'], $_POST['lng']) ) {
die('missing parameters'); // you probably want a slightly more sophisticated error handling here
}
session_start();
$_SESSION['lat']=$_POST['lat'];
$_SESSION['lng']=$_POST['lng'];
//session_write_close();
//header('Location: http://sample.com/e_health/searchambulance.php');
echo 'session_id=', session_id(), '<br /><a href="http://sample.com/e_health/searchambulance.php">page #2</a>';
file2的:
<?php
session_start();
$lat= $_SESSION['lat'];
$lng=$_SESSION['lng'];
echo 'session_id=', session_id(), '<br />';
echo $lat;
echo $lng;
答案 1 :(得分:0)
以这种方式更改代码。它会起作用......
file1.php:
<?php
session_start();
$_SESSION['lat']=$_POST['lat'];
$_SESSION['lng']=$_POST['lng'];
header('Location: http://sample.com/e_health/searchambulance.php');
?>
file2:
<?php
session_start();
$lat= $_SESSION['lat'];
$lng=$_SESSION['lng'];
echo $lat;
echo $lng;
?>