-1

我使用header传递参数,但没有工作

这是第1页:

session_start();

$_SESSION['favcolor'] = 'green';
$_SESSION['animal']   = 'cat';
$_SESSION['time']     = time();
$problem  = "correct";

header('Location:trynew2.php?problem=$problem');

?>

这是我的第二页:

<?php
session_start();

echo "welcome" ;
$problem = $_GET['problem'];
echo $problem;

$test = $_SESSION['favcolor'];
echo $test;
?>

结果很受欢迎$problemgreen

4

2 回答 2

2

使用单引号只会回显您在其中输入的内容,并且不会处理变量。您需要在标题行上使用双引号

header("Location:trynew2.php?problem=$problem");
于 2013-07-19T18:17:35.833 回答
0
header('Location:trynew2.php?problem=$problem');

这会将您发送到具有以下 URL 的下一页:

trynew2.php?problem=$problem

单引号不插入变量;如果您希望它按预期运行,则需要使用双引号:

header("Location:trynew2.php?problem=$problem");
于 2013-07-19T18:17:29.567 回答