Hi Guys,
Using Heredocs, I am getting a parse error. Here is the error:
Parse error: parse error, expecting `']'' in /someURL/exercise2.php on line 73
The error is referring to the second $_SESSION[] entry in the HTML from the following PHP code.
Here is the code:
<?php
include '../../../functions.inc.php';
$auth = authenticate();//run the authenticate script from functions.inc.php
if ($auth !='true') {
header("Location: [url]http://myclass.missouri.edu/~mms42b/new/login/login.html[/url]"); // Redirect browser */
exit;
}
// Name session and add responses to session
$_SESSION['module'] = "Selenium";
//define variables passed by POST and add them to the session
foreach ($HTTP_POST_VARS as $k=>$v){
if ($k != "submit") {
$_SESSION[$k] = $v;
}
}
//ensure that the form was completely filled out
while (list($k, $v) = each($_SESSION)) {
if ($v != "") {
$allow = "true";
} else {
$allow = "false";
}
}
if ($allow = "true") {
//build the HTML page
print <<< HTML
<html>
<head>
<title>exercise2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body background="../../images/background.jpg">
<!--begin main table-->
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="0" class="sitestyle">
<tr>
<td width="65%" bgcolor="#000000"><a href="../../index.html"><img src="../../images/logo.gif" name="logo" width="595" height="68" border="0" id="logo"></a></td>
<td width="35%" bgcolor="#000000"> </td>
</tr>
<tr>
<td colspan="2"><div align="center">
<p> </p>
<p align="center"><font face="Arial, Helvetica, sans-serif"><strong><font size="4"><span class="sitestyle">Application
of Nuclear Methodologies to Identify the Source of Obsidian Artifacts</span></font></strong><br>
</font></p>
<!--begin subtable-->
<table align="center" width=75% border="1" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td bordercolor="#000000" bgcolor="#999999"> <p align="left"><font face="Arial, Helvetica, sans-serif"><strong>Results
Page </strong></font></p></td>
</tr>
<td bordercolor="#000000" bgcolor=#E6E6E6>
<p><font face="arial" size=2>You chose <b>$_SESSION[1]]>
as your method of choice for conducting elemental analysis on your
obsidian samples.<br>
<br>
Your reasoning for choosing this method is as follows:<br>
<br>
<em>$_SESSION[1a]</em><br>
<!--etc. etc. etc.-->
<p align="center"><font size="2" face="arial"><a href="exercise3.php">Continue</a></font></p>
</td>
</table>
</table>
</body>
</html>
HTML;
} else {
echo "<h1>Error</h1><p>You must fill out <b>all</b> fields. Please use your browser's \"back\" button and complete all fields.</p>";
} //end if statement
?>
Why am I getting this parse error? When I laboriously assign variables to each SESSION key and value (ex.,
$answer1a=$_SESSION[1a];
and code the variables into the HTML instead of the $_SESSION the problem goes away. The problem persists, however, if I use $_POST[] values. I assume it's a heredoc problem. Is anyone aware of heredoc problems with the characters "[" and "]"? Can you guys please point me in the right direction?
Thank you for your help!
matty-x 😃