【发布时间】:2022-01-03 05:51:39
【问题描述】:
我在运行 php 脚本时遇到问题,使用 header() 调用第二个脚本。
主脚本 (a.php) 在运行时调用第二个脚本 (b.php)。
当使用此表单时,一切都按预期进行(执行ActionA 和ActionB):
https://example.com/a.php
使用此其他形式时,不会发生预期的行为(ActionAX 和 ActionBX)。而是执行 ActionAX 和 ActionB:
https://example.com/a.php?V=X
换句话说,b.php 没有得到 V=X 位的信息。
a.php 文件如下所示:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<META HTTP-EQUIV="content-type" CONTENT="text/html; CHARSET=UTF-8">
<TITLE>MyWebApp</TITLE>
<STYLE>
INPUT[type='Submit'] {font-size: 19px;}
</STYLE>
</HEAD>
<BODY bgcolor="#A1E3D2">
<?php
session_start();
.....
function getVarStr()
{/* Beginning of getVarStr */
if ($_GET['V'] == 'X') performActionAX();
else performActionA();
}/* End of getVarStr */
.....
getVarStr();
.....
if ($_GET['V'] == 'X') header("Location: ./b.php?V=X");
header("Location: ./b.php");
.....
?>
</BODY>
</HTML>
b.php 文件如下所示:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Extra Page</title>
<STYLE>
INPUT[type='Submit'] {font-size: 19px;}
</STYLE>
</head>
<body>
<?php
session_start();
.....
function getVarStr()
{/* Beginning of getVarStr */
if ($_GET['V'] == 'X') performActionBX();
else performActionB();
}/* End of getVarStr */
.....
getVarStr();
.....
?>
</BODY>
</HTML>
谁能指出我犯的错误?
我也尝试过使用会话变量来处理这个问题,但我遇到了完全相同的问题。
在这种情况下,我将 b.php 中的 getVarStr() 更改为:
function getVarStr()
{/* Beginning of getVarStr */
if ($_SESSION['V'] == 'X') performActionBX();
else performActionB();
}/* End of getVarStr */
【问题讨论】:
标签: php http-headers