'Unexpected $ in....' on my live server, NOT on 2 others..

A

Anonymous

Guest
I've written a number of PHP-driven sites, but have never seen the following:

I have developed a site on my WinXP laptop (Apache 2.0.44, PHP4.3.1). When I wanted to test it on my hosted development site (Linux, Apache1.3.27, PHP4.3.1), it gave me the following error:
Parse error: parse error, unexpected $ in left_column.inc.php on line 1

Looking over all the brackets did not solve anything.

When I uploaded it to a second hosted server (our companies website 8) with Linux, Apache 1.3.22, PHP4.2.2), it worked without a hitch at first upload..

I'm stumped.. I have used this hosting provider for years and for several websites, but I have never seen this happen.

Does anybody have a clue?

Thanks!

Cas
 
The code consists of an index file with several switched includes, based on the 'main'-variable. All the output is added to the $body-variable, which is echoed at the end of the script. This allows me to easily do replacements and highlighting to the whole page.

The includes for 'header' and 'footer' contain plain HTML which is added to the body-tag.
e.g.:
Code:
<?
$body.="<img src=\"headerimg.gif\" border=0>";
?>

I Googled for the 'unexpected $' but the only thing I found were people replying to check the brackets and interpunction.

Code:
require("./includes/config.inc.php"); //-> MySQL config settings e.d.
include("./includes/head-sect.inc.php"); //-> <head>-tag of the page

// The body is ALWAYS in a table. Let's now create the master table
$body .= "<table width=800 border=0 cellpadding=0 cellspacing=0>
	<tr><td>";
include ("./includes/header.inc.php"); // include page header, add some plain HMTL to the $body-tag
$body .= "</td></tr>";

///////////////////////
// Create master row, containing a left-column (for menu), spacer column and right column (for content)
$body .= "<tr>"; 
	//Run left column here
	$body .= "<td width=$mcol_left height=550 valign=top>";
		include("./includes/left_column.inc.php");
	$body .= "</td>"; 
	
	// Insert spacer column	
	$body .= "<td width=$mcol_spacer valign=top> </td>";
	
	//Run main-section here
	$body .= "<td width=$mcol_right height=550 valign=top>";
		include("./includes/right_column.inc.php");
	$body .="</td>";
// End the master row
$body .="</tr>";

// insert footer 
include ("./includes/footer.inc.php");
$body .= "</table>
</BODY>
<HTML>";

///////////////////////////////////
if(!isset($title)){$title=":: Welcome to my website ::";}
if ((!isset($std_css))) {$std_css="<LINK REL=\"STYLESHEET\" TYPE=\"text/css\" HREF=\"./includes/standard.css\">";}

// If needed, do some replacements to $body
$body = eregi_replace("{{{TITLE}}}",$title,$body);
$body = eregi_replace("{{{std_css}}}",$std_css,$body);
$body = eregi_replace("{{{add_css}}}",$add_css,$body);
$body = eregi_replace("{{{headscript}}}",$headscript,$body);
$body = eregi_replace("{{{onload}}}",$onload,$body);

// Highlight any text that needs to be highlighted
if(isset($highlight)){
	$body = eregi_replace ("$highlight","<span style=\"background-color: yellow\"><font color=red size=2><b>$highlight</b></font></span>",$body);
	}

echo $body;

What I do not understand, is that the unchanged script runs on a Windows machine and a Linux machine without any problems or errors (I have viewed the source of the page and no 'hidden' errors were shown), but when I upload it to another server,

Register_Globals is ON on all 3 machines.

Even by remarking the complete content of the left_column.inc.php (except the <? and ?> brackets), the problem remains....

Could it have something to do with the server setup?

Thanks in advance,

Cas
 
mollien said:
Code:
<?
$body.="<img src="headerimg.gif" border=0>";
?>

The problem is likely that the server which is returning the error has error-reporting for Notices turned on, while the other two don't. Notices are small errors that won't stop a program from running (PHP 'works around' them), but which are still errors. Notice reporting is turned off by default in PHP. Above, it looks like you're trying to append text to a string ($body) before the variable is created (e.g. it's bad form to append text to a variable that doesn't exist). PHP knows how to work around this (it just automatically creates the variable before appending), but if Notice-reporting is turned on, it will still return an error before going about its business. Now, some people would fix this by just turning off Notice-reporting (this is a setting in PHP.ini), but this is just fixing the symptom, not the problem. The right way to fix this is by just making sure your variables are initialized before you try to manipulate them:

Code:
<?
$body = ''; // initialize the variable before you try to manipulate it
$body .= "<img src="headerimg.gif" border=0>";
?>
 
Great Swirlee, I did not know that. I'm going to check the declaration of my variables.

I have checked phpinfo(); for 'notices', but have not been able to find it. How can I check if notices are turned on or off? Doe this have anything to do with the 'Magic Quotes', as I noticed that these are 'off' on my live server?

Thanks,

Cas
 
Guys, thanks for the helpful sugeestions. I know my coding is far from perfect, and some pointers on how to clean my code are always helpful.. :)

Anyway, I think I have isolated the problem (after almost 2 days :evil: ). It seems that my live server has a problem with remarks:
Code:
while($option=mysql_fetch_row($result)){
	//get all menu options and make a link for each...
	if ($option[0]!=$tmpheader) {
	    $body .= $spacer_row;
		$body .= "<tr><td class=\"submenu\">$option[0]</td></tr>";
		$tmpheader=$option[0];
	}

When I take out the remarked line, the script runs. :?

Now, another weird part.

In the end of the script I close some tables. Behind the lines, I remark which table I close:
Code:
$body .= "</form></table>"; // End Login-table
$body .= "</td><tr></table>"; // End Menu Options Table
$body .= "</td></tr></table>"; // End Left Column Table

In this case, the double slash remarks the whole line!!

Yet, if I remark like this:
Code:
$body .= "</form></table>"; /* End Login-table */
$body .= "</td><tr></table>"; /* End Menu Options Table */
$body .= "</td></tr></table>"; /* End Left Column Table */

everything seems to work just fine...

I am completely puzzled, since double slashes have never given me a problem before... Even in other parts of the script where double slashed are used to document my actions, sometimes it works, sometimes it does not.

I will go ahead and remark everything 'new style', but I would definately like to know why this is happening.

Can anybody point me in a specific direction? Is this a server-setting? Can this behaviour be influenced by the script (e.g.: by adding some command)?

Again, your input would be greatly appreciated.

Thanks,

Cas
 
Since this is a different question alltogether, I'll post it in a new topic.

To all, thanks for your help on this matter..

Cas
 
Back
Top