Page 1 of 1
Parse Error :(
Posted: Sun Jan 23, 2005 7:05 am
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

I've been working to fix it for hours.
Posted: Sun Jan 23, 2005 7:48 am
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'){
$ip = $_SERVERї'REMOTE_ADDR'];
$fp = fopen("ips.dat", "r");
while(!feof($fp)){
$check = fgets($fp);
if($ip == $check){ $ipsame = true; } else { $ipsame = false; };
}
fclose($fp);
if($ipsame == false){
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ї'REMOTE_ADDR'];
fputs($fp, $ip);
fclose($fp);
} else {
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>.";
}
} else {
if($username == NULL){
echo "<form method="post"><b>» Username</b><br><input type="text" name="username" maxlength="10"><br><br><b>» 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!\> | <input type="reset" value="Reset"></form>";
} else {
$username = trim($username);
$charusername = strlen($username);
if($charusername < 4 || $charusername > 10){
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;
} else {}
if(!eregi("^їa-z0-9_]+@їa-z0-9\-]+\.їa-z0-9\-\.]+$", $email)){
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;
} else {}
if($notify == TRUE){ $notify = "Yes"; } else { $notify = "No"; }
if($userbad = 1 || $emailbad = 1){
echo "<b>Sign-up process failed.</b>";
} else {
function random_char($string) {
$length = strlen($tring);
$position = mt_rand(0, $length - 1);
return($stringї$position]);
}
function random_string ($charset_string, $length)
{
$return_string = "";
for ($x = 0; $x < $length; $x++)
$return_string .= random_char($charset_string);
return($return_string);
}
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";
}
}
?><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>
Posted: Sun Jan 23, 2005 7:51 am
by feyd
the first if's else is not closed.
Posted: Sun Jan 23, 2005 8:00 am
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

Posted: Sun Jan 23, 2005 8:05 am
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 )
{
code line;
code line;
code line;
}
function functionName(argument1,...)
{
code line;
code line;
code line;
}
Posted: Sun Jan 23, 2005 9:39 am
by choco
Yeh, that's me for ya
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
Posted: Sun Jan 23, 2005 9:51 am
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'){ setcookie("zdbandwidth", $bandwidth, time() * 3600 * 60 * 60 * 24); header("Location: http://www.zelda-dimension.net/"); exit;} elseif($bandwidth == "clear"){ setcookie("zdbandwidth", $abc, time() * 3600 * 60 * 60 * 24); header("Location: http://www.zelda-dimension.net/"); exit;} else {}
if($username == '' || $password == ''){ header("Location: http://www.zelda-dimension.net?id={$id}&com=nu"); }
$fp = fopen("usernames.txt", "r");
while(!feof($fp)){
$check = fgets($fp);
if ($username == $check){ $usermatch = TRUE; } else {}
$i++;
}
fclose($fp);
if($usermatch != TRUE){ header("Location: http://www.zelda-dimension.net?com=nu"); } else {
$fp = fopen("passwords.txt", "r");
$md5pass = md5($password);
while($i > 0){
$check = fgets($fp);
if ($md5pass == $check){ $passmatch = TRUE; } else {}
$i - 1;
}
fclose($fp);
if($passmatch != TRUE){ header("Location: http://www.zelda-dimension.net?com=nu"); } else {}
if($passmatch == TRUE && $usermatch == TRUE){ header("Location: http://www.zelda-dimension.net/s2.php?username={$username}&password={$password}"); } else {}
}
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
By the way, I won't be replying to replies because I have to go to bed now (it's 2:30 AM

)
Posted: Sun Jan 23, 2005 10:04 am
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.

Posted: Sun Jan 23, 2005 8:40 pm
by choco
Thanks, you're a legend m8
