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!
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.
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.
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>
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?
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.