Page 1 of 1

quick newbie Q - script pase error

Posted: Thu Aug 12, 2004 11:16 am
by scottbradentx
feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi, my first post, total php newbie so I'm following cut n paste instructions without really understanding the syntax or rules. 

Here's my script:

Code: Select all

<html>
<head>
</head>
<title> 
</title>
<body>
<?php
$link1='www.microsoft-secrets.com';
$link2='www.microsoft-licensing.com';

$tr1='50';
$tr2='50';

$filename="MSLS1.log";

$tr1=$tr1+0;

if($tr2>0){
 $tr2=$tr2+$tr1;
}else{
 $tr2=0;
}



$secm100=floor(100*(date("s")+1)/60);

if ($secm100 >0 && $secm100 <= $tr1){
	$url=$link1;
}elseif($secm100 > $tr1 && $secm100 <= $tr2){
	$url=$link2;

if (!isset($_COOKIE['uvst'])){
	setcookie ("uvst",$url);
    if ($fh = fopen($filename, "a+")){
        fwrite($fh, $url."\n");
       fclose($fh);
    }
}else{
	$url=$_COOKIE['uvst'];
}

header("HTTP/1.1 301 Moved Permanently");
header("Location: $url");

?>

</body>
</html>
(end script)

And here's the error I get when I hit http://www.mysite.com/mls.php:

Parse error: parse error, unexpected $ in /homepages/27/d100590837/htdocs/mls.php on line 51

So... I'm sure it's obvious to you - what siple error have I made?

Thanks
Scott


feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Thu Aug 12, 2004 12:33 pm
by Buddha443556
The most obvious problem I see is the header() probably isn't going to work with all the HTML output.

Get rid of this

Code: Select all

<html> 
<head> 
</head> 
<title> 
</title> 
<body>
and

Code: Select all

</body> 
</html>
and any whitespace before <?php and after ? >.

Posted: Thu Aug 12, 2004 12:39 pm
by feyd
btw, the second if, isn't being closed.

Posted: Thu Aug 12, 2004 12:49 pm
by Buddha443556
To illustrate Feyd answer.

This ....

Code: Select all

if ($secm100 >0 && $secm100 <= $tr1){ 
   $url=$link1; 
}elseif($secm100 > $tr1 && $secm100 <= $tr2){ 
   $url=$link2;
should look like this ...

Code: Select all

if ($secm100 >0 && $secm100 <= $tr1){ 
   $url=$link1; 
}elseif($secm100 > $tr1 && $secm100 <= $tr2){ 
   $url=$link2;
}
notice the closing } brace?