lszanto Posted February 4, 2007 Share Posted February 4, 2007 I have been working on this website and for some reason when somebody registers the php just dies and the bottom of the page goes blank. When I block out the check_ip() funciton and the part of the code using it the page runs fine but I can't work out what the problem is, please help. <?php include "connect.php"; function getip() { $ip = ""; if (isset($_SERVER)) { if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) { $ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; } elseif (isset($_SERVER["HTTP_CLIENT_IP"])) { $ip = $_SERVER["HTTP_CLIENT_IP"]; } else { $ip = $_SERVER["REMOTE_ADDR"]; } } else { if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) { $ip = getenv( 'HTTP_X_FORWARDED_FOR' ); } elseif ( getenv( 'HTTP_CLIENT_IP' ) ) { $ip = getenv( 'HTTP_CLIENT_IP' ); } else { $ip = getenv( 'REMOTE_ADDR' ); } } return $ip; } function check_ip($ip) { //Check to see if ip is already registered. $sql = "SELECT ip FROM users WHERE ip='$ip'"; //Do query. $result = mysql_num_rows(mysql_query($sql)) or die(mysql_error()); if($result > 0) { return false; } else { return true; } } function check_email_address($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>FFI Rail Jam.</title> <link rel="stylesheet" type="text/css" href="css/layout.css" media="screen, projection, tv " /> <link rel="stylesheet" type="text/css" href="css/html.css" media="screen, projection, tv " /> </head> <body> <div id="content"> <?php include "header.php"; ?> <div id="headerImg" class="width"></div> <?php include "menu.php"; ?> <div id="page"> <div id="columns" class="widthPad"> <!-- Left column --> <?php if(isset($_POST['subed'])) { $name = trim($_POST['name']); $password = trim($_POST['password']); $passcheck = trim($_POST['passcheck']); $email = trim($_POST['email']); $country = trim($_POST['country']); $address = trim($_POST['address']); $ip = $_POST['ip']; $video = "false"; $rank = "pending"; $code = rand(1, 10000); $errors = 0; $include = true; if(!check_ip($ip)) { echo "A person has already registered with this ip, I'm sorry you can only have one person per ip otherwise you are suspected of having mutiple accounts if this is a problem please contact us <a href=\"contact.php\" >here</a>.<br />\n"; $errors++; } if(empty($name)) { echo "\nYou left the \"Full Name\" field blank, please go <a href=\"{$_SERVER['HTTP_REFERER']}\" >back</a> and correct this field.<br />\n"; $errors++; } if(empty($password) || empty($passcheck)) { if(isset($name)) { echo "Errors:<br />\n"; } echo "You left one of the password fields blank, please go <a href=\"{$_SERVER['HTTP_REFERER']}\" >back</a> and correct these fields.<br />\n"; $errors++; } if(empty($email)) { if(isset($name) && isset($password) && isset($passcheck)) { echo "Errors:<br />\n"; } echo "You left the \"Email\" field blank, please go <a href=\"{$_SERVER['HTTP_REFERER']}\" >back</a> and correct this field.<br />\n"; $errors++; } if(!check_email_address($email)) { if(isset($name) && isset($password) && isset($passcheck) && isset($email)) { echo "Errors:<br />\n"; } echo "Your email address is not valid, please go <a href=\"{$_SERVER['HTTP_REFERER']}\" >back</a> and correct this field.<br />\n"; $mail = "invalid"; $errors++; } if(empty($country)) { if(isset($name) && isset($password) && isset($passcheck) && isset($email) && $mail == "valid") { echo "Errors:<br />\n"; } echo "You left the \"Country\" field blank, please go <a href=\"{$_SERVER['HTTP_REFERER']}\" >back</a> and correct this field.<br />\n"; $errors++; } if(empty($address)) { if(isset($name) && isset($password) && isset($passcheck) && isset($email) && isset($country)) { echo "Errors:<br />\n"; } echo "You left the \"Address\" field blank, please go <a href=\"{$_SERVER['HTTP_REFERER']}\" >back</a> and correct this field.<br />\n"; } if($errors == 0) { //Make query. $sql = "INSERT INTO users(username, password, email, country, address, ip, video, rank, code, id) values('$name', '$password', '$email', '$country', '$address', '$ip', '$video', '$rank', '$code', Null)"; //Insert user. mysql_query($sql) or die(mysql_error()); //Start email. $to = $email; $subject = "FFI Rail Jam Registration."; $headers = "From: FingerFlipInc\n"; $message = "Hello, $name\nThankyou for signing up at the FFI Rail Jam, below are your login details.\n\nUsername: $name\nPassword: $password\n\nBefore logging in you must validate your account with the number $code, please click here to do so:\nhttp://fingerflipinc.com/contest/pages.php?action=validate\n\nThanks, Admin."; $themail = mail($to, $subject, $message, $headers); if($themail) { echo "Thankyou for registering, " . $name . " you should receive an email with login details if you are using hotmail, gmail or yahoo mail please check in your junk mail."; } else { die("Error in registering, please go <a href=\"{$_SERVER['HTTP_REFERER']}\" >back</a> and correct the form then try again."); } } else { echo "\n<br />\nYou made $errors errors, please go <a href=\"{$_SERVER['HTTP_REFERER']}\" >back</a> and correct the form then try again."; } } else { ?> <div class="floatLeft width25 lightBlueBg horzPad"> <h2>Details</h2> <p> Please make sure you fill out all fields correctly otherwise your account will be deleted an you won't be able to submit a video. </p> <br style="clear: both;"> </div> <!-- Left column end --> <!-- Right column --> <div class="floatRight width73"> <h1>Regi<span class="dark">ster</span></h1> <p> To register please fill in all the below forms and click send, making sure no fields are blank. Please give all valid information because if it is not valid we will not be able to send your prizes if you win. </p> <form id="contact" action="register.php" method="post" style="position: relative; z-index: 1;" name="register" > <input type="hidden" name="ip" value="<?php echo getip(); ?>" /> <p> <input name="name" value="Full Name" class="width75" onFocus=" register.name.value = ''; " type="text" /> </p> <p> <input name="password" value="Password" class="width75" onFocus=" register.password.type = 'password'; register.password.value = ''; " type="text" /> </p> <p> <input name="passcheck" value="Verify Password" class="width75" onFocus=" register.passcheck.type = 'password'; register.passcheck.value = ''; " type="text" /> </p> <p> <input name="email" value="Valid E-mail Address" class="width75" onFocus=" register.email.value = ''; " type="text" /> </p> <p> <input name="country" value="Country" class="width75" onFocus=" register.country.value = ''; " type="text" /> </p> <p> <textarea name="address" rows="5" cols="80" onFocus=" register.address.value = ''; " >Address</textarea> </p> <p> <input value="Send" class="button" type="submit" name="subed" /> <input value="Reset" class="button" onClick=" register.password.type = 'text'; register.passcheck.type = 'text'; " type="reset" /> </p> <p> </p> <?php } include "rightclm.php"; ?> </div> <!-- Right links column end --> </div> <!-- #columns end --> </div> <!-- #page end --> <div style="clear:both;"></div> </div> <!-- #content end --> <?php include "footer.php"; ?> Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/37020-unknown-problem/ Share on other sites More sharing options...
hvle Posted February 4, 2007 Share Posted February 4, 2007 if the problem lies on the check_ip() function, I've revised the check_ip function function check_ip($ip) { //Check to see if ip is already registered. $sql = "SELECT count(*) FROM users WHERE ip='$ip'"; $result = mysql_query($sql) or die("can not query database"); $row = mysql_fetch_row($result); if($row[0] > 0) return false; return true; } Link to comment https://forums.phpfreaks.com/topic/37020-unknown-problem/#findComment-176746 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.