Parse Error :(

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
choco
Forum Newbie
Posts: 6
Joined: Sun Jan 23, 2005 6:55 am
Location: Behind the BenQ ;)

Parse Error :(

Post by choco »

I've been having a problem in PHP with a parse error. Basically, it's a script I'm working on for a member registration thing. I get the error message that says:

Parse error: parse error, unexpected $ in /home/choco/public_html/signup.cfm on line 147

Now, I'm puzzled with it. I know that the unexpected $ part means that there is an unclosed bracket, quote or semicolon, doesn't it? But the issue is that I can't find it. I've been programming for a while, and I have made a few custom scripts for my site.

You can view the actual file at http://www.zelda-dimension.net/index.php?id=signup, and I also slapped it in a flat text file for easier reading (http://www.zelda-dimension.net/signup.txt.

Note: With the text file, don't worry about me not having the <html>, <head> etc. coding, my index.php does all that. Also, line 147 is the end of my coding, the line itself includes ?>

I hope you can help me :cry: I've been working to fix it for hours.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

For everyone's ease of use, the text file linked to:

Code: Select all

Member Registration
</font><br>
Here is where you can register to be a member of The Zelda Dimension. Registering allows benefits such as getting the latest game information updated, and at a later stage you 
will be able to be notified once a month of updates and changes to the site. Registering includes several easy steps which is simple and contains instant activation. Just hit "Sign Up!" 
your password will be e-mailed to you. Your username can be between four and ten characters.<br>

<?php
if($com == 'act')&#123;
















$ip = $_SERVER&#1111;'REMOTE_ADDR'];
$fp = fopen("ips.dat", "r");
while(!feof($fp))&#123;
	$check = fgets($fp);
	if($ip == $check)&#123; $ipsame = true; &#125; else &#123; $ipsame = false; &#125;;
&#125;
fclose($fp);

if($ipsame == false)&#123;
echo "<b>Registration Successful!</b><br>
<br>
Congratulations, your registration was successful. You can now sign in on the submenu to the right to view the latest and most up-to-date information...from me :p";
$a = fopen("usernames.dat","a");
$b = fopen("passwords.dat","a");
$c = fopen("notify.dat","a");

$usr = "\n" . $usr;
$w = "\n" . $w;
$nf = "\n". $nf;

fputs($a, $usr);
fputs($b, $w);
fputs($c, $nf);

fclose($a);
fclose($b);
fclose($c);

$fp = fopen("ips.dat", "r");
$ip = "\n" . $_SERVER&#1111;'REMOTE_ADDR'];
fputs($fp, $ip);
fclose($fp);

&#125; else &#123;

echo "Your IP address has already been registered with an account. If you would like your password resent, please use my <d href="index.php?id=resetpass">Password Reset Form</a>.";
&#125;











&#125; else &#123;















if($username == NULL)&#123;

echo "<form method="post"><b>&raquo; Username</b><br><input type="text" name="username" maxlength="10"><br><br><b>&raquo; E-mail Address</b><br><input type="text" name="email"><br><br>Notify me of updates once a month<br><input type="checkbox" name="notify" checked><br><input type="submit" value="Sign up!\>&nbsp;|&nbsp;<input type="reset" value="Reset"></form>";

&#125; else &#123;
$username = trim($username);
$charusername = strlen($username);

if($charusername < 4 || $charusername > 10)&#123;
echo "<b><font color=red>Error</font></b>: Your username was either less than four characters or more than ten characters. Please <a href="javascript:history.go(-1);">return</a> to the previous page and try again.<br>";
$userbad = 1;
&#125; else &#123;&#125;

if(!eregi("^&#1111;a-z0-9_]+@&#1111;a-z0-9\-]+\.&#1111;a-z0-9\-\.]+$", $email))&#123;
echo "<b><font color=red>Error</font></b>: Your e-mail address is invalid. Please <a href="javascript:history.go(-1);">return</a> to the previous page and try again.<br>";
$emailbad = 1;
&#125; else &#123;&#125;

if($notify == TRUE)&#123; $notify = "Yes"; &#125; else &#123; $notify = "No"; &#125;

if($userbad = 1 || $emailbad = 1)&#123;
echo "<b>Sign-up process failed.</b>"; 
&#125; else &#123;

function random_char($string) &#123;
	$length = strlen($tring);
	$position = mt_rand(0, $length - 1);
	return($string&#1111;$position]);
&#125;
function random_string ($charset_string, $length)
&#123;
	$return_string = "";
	for ($x = 0; $x < $length; $x++)
	$return_string .= random_char($charset_string);
	return($return_string);
&#125;
mt_srand((double)microtime() * 1000000);
$charset = "abcdefghijklmnopqrstuvwxyz0123456789";
$password = random_string($charset, 8);
$pswd = md5($password);

$msg = "Dear $username, \n You or someone else has registered at The Zelda Dimension (www.zelda-dimension.net) earlier today for membership. The following details were assigned: \n \n
Username: \t$username \n Password: \t$password \n \n Notify of Updates: \t$notify \n \n To activate this account, copy the following text and 
paste it in your browser URL bar. \n \n http://www.zelda-dimension.net/index.php?id=signup&com=act&usr=$username&w=$pswd&nf=$notify\n\n Thankyou for registering, $username. \n \n
The Zelda Dimension";

$mailheaders  = "MIME-Version: 1.0\r\n";
$mailheaders .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$mailheaders .= "From: signup@zelda-dimension.net <signup@zelda-dimension.net>\r\n";
$mailheaders .= "Reply-To: signup@zelda-dimension.net <signup@zelda-dimension.net>\r\n"; 
mail("webmaster@zelda-dimension.net","The Zelda Dimension Sign-up",stripslashes($msg), $mailheaders);

echo "Your details and password have been sent to $email. Your details are below:<br><br>Username: $username<br>Password: Auto-generated (see e-mail)<br>Message: ";
echo nl2br(stripslashes($msg));
echo "<br>Notify of updates: $notify";

	&#125;
&#125;
?><p align=center>

<script type="text/javascript"><!--
google_ad_client = "pub-2309019366929417";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_channel ="";
google_color_border = "CCCCCC";
google_color_bg = "FFFFFF";
google_color_link = "000000";
google_color_url = "666666";
google_color_text = "333333";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br>
<a href=http://www.fwsh.com/cgi-bin/cp.exe?page=counter><img border=0 src=http://ads.fwsh.com/subbanner.gif></a>
</p>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the first if's else is not closed.
choco
Forum Newbie
Posts: 6
Joined: Sun Jan 23, 2005 6:55 am
Location: Behind the BenQ ;)

Post by choco »

Ummmmm........sorry about that. I was worried about the file being too big to post, oh well :p

Sorry to bother you and all.....um.....I'm embarrassed :oops:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

don't worry about it.. I just post the files because I know I'd want to see the code in the thread so I don't have to click elsewhere. ;)

I can only suggest using a slightly less compact, and at least for me, much more readable style, and remember to use indentation:

Code: Select all

if( expression )
&#123;
  code line;
  code line;
  code line;
&#125;


function functionName(argument1,...)
&#123;
  code line;
  code line;
  code line;
&#125;
choco
Forum Newbie
Posts: 6
Joined: Sun Jan 23, 2005 6:55 am
Location: Behind the BenQ ;)

Post by choco »

Yeh, that's me for ya :D

I was self-taught by myself, and I've always been a messy kind of person. Maybe I'll become neater as I grow :? oh well
choco
Forum Newbie
Posts: 6
Joined: Sun Jan 23, 2005 6:55 am
Location: Behind the BenQ ;)

Post by choco »

The other problem I'm having is s1.php, which will NOT load at all. It is the processing page for the login, but it won't work :( its function is to redirect. It supports my low-bandwidth cookie mode, and also the login script. After the login is determined to be a success from the database, it redirects to s2.php, which sets the logged-in cookie and redirects to the main page :? get that?

Here is s1.php

Code: Select all

<?php
$abc = NULL;
if($bandwidth == '1')&#123; setcookie("zdbandwidth", $bandwidth, time() * 3600 * 60 * 60 * 24); header("Location: http://www.zelda-dimension.net/"); exit;&#125; elseif($bandwidth == "clear")&#123; setcookie("zdbandwidth", $abc, time() * 3600 * 60 * 60 * 24); header("Location: http://www.zelda-dimension.net/"); exit;&#125; else &#123;&#125;

if($username == '' || $password == '')&#123; header("Location: http://www.zelda-dimension.net?id=&#123;$id&#125;&com=nu"); &#125;
$fp = fopen("usernames.txt", "r");
while(!feof($fp))&#123;
	$check = fgets($fp);
	if ($username == $check)&#123; $usermatch = TRUE; &#125; else &#123;&#125;
	$i++;
&#125;
fclose($fp);
if($usermatch != TRUE)&#123; header("Location: http://www.zelda-dimension.net?com=nu"); &#125; else &#123;

$fp = fopen("passwords.txt", "r");
$md5pass = md5($password);
while($i > 0)&#123;
	$check = fgets($fp);
	if ($md5pass == $check)&#123; $passmatch = TRUE; &#125; else &#123;&#125;
	$i - 1;
&#125;
fclose($fp);
if($passmatch != TRUE)&#123; header("Location: http://www.zelda-dimension.net?com=nu"); &#125; else &#123;&#125;



if($passmatch == TRUE && $usermatch == TRUE)&#123; header("Location: http://www.zelda-dimension.net/s2.php?username=&#123;$username&#125;&password=&#123;$password&#125;"); &#125; else &#123;&#125;

&#125;


header ("Location: http://www.zelda-dimension.net/");
?>

Here is s2.php

Code: Select all

<?php
setcookie("zdloggedin", $username, time() * 3600 * 60 * 60 * 24);
header("Location: http://www.zelda-dimension.net");
exit;
?>
Thanks once again :D

By the way, I won't be replying to replies because I have to go to bed now (it's 2:30 AM 8O )
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your redirect url's may be at fault: http://www.zelda-dimension.net?id={$id}&com=nu
it may need a / after the domain, I'm not entirely sure.

Also the expiry time you are giving, doesn't exist. i.e. the number result is too large. I think you mean to use: time() + 3600 * 24, to make it expire tomorrow, or time() + 3600 * 60 * 24, to expire in 2 months.. At any rate, you probably want to add a certain amount of time to this moment.. currently you're multiplying it. ;)
choco
Forum Newbie
Posts: 6
Joined: Sun Jan 23, 2005 6:55 am
Location: Behind the BenQ ;)

Post by choco »

Thanks, you're a legend m8 :D
Post Reply