I have a problem when running a php script, calling a second script using header().
The main script (a.php) calls, while running, a second script (b.php).
When using this form all goes as expected (ActionA and ActionB are performed):
https://example.com/a.php
When using this other form, the expected behavior (ActionAX and ActionBX) is not taking place. Instead ActionAX and ActionB are performed:
https://example.com/a.php?V=X
In other words b.php does not get the V=X bit of information.
The file a.php looks like this:
<!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>
The file b.php looks like this:
<!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>
Can anyone point out a mistake I am making ?
I have also tried to handle the issue using session variables, but I hit exactly the same problem.
I this case I change the getVarStr() inside b.php to:
function getVarStr()
{/* Beginning of getVarStr */
if ($_SESSION['V'] == 'X') performActionBX();
else performActionB();
}/* End of getVarStr */