April 8, 201016 yr Hi there. I am having trouble with a script which used to work but since moving to a new host I have changed a lot. Could someone please help me find where I am going wrong because the error I get doesn't give any kind of clue to what is wrong and I just can't figure it out. Here's the code: <?php //GET key: 1=not logged in, 2=user non-existant, 3=wrong password, 4=fields blank, 5=registered now login, 6=user already exists, 7=passwords don't match, 8=emails don't match, 9=email not sent //This checks for invalid inputs function checkOK($field) { if (strstr("\r",$field) || strstr("\n",$field)) { die("Invalid Input!"); } } //random string generator function randstr($md5 = "no", $length = "32", $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890') { //character list length $char_length = (strlen($chars) - 1); //start the string $string = $chars{rand(0, $char_length)}; //generate string characters for ($i = 1; $i < $length; $i = strlen($string)) { //Generate a random character from the list $c = $chars{rand(0, $chars_length)}; //make sure same characters don't appear together if ($c != $string{$i - 1}) { //add letter to string $string .= $c; } } //optional md5 encryption if ($md5 == "md5") { $string = md5($string); } //return the string return $string; } //This code runs if the form has been submitted if (isset($_POST['Submit'])) { //This makes sure they did not leave any fields blank if ((!$user) || (!$pass) || (!$pass2) || (!$email) || (!$email2)) { header("Location: register.php?reason=4"); } //make field values into variables $user = $_POST['user']; checkOK($user); $pass = $_POST['pass']; checkOK($pass); $pass2 = $_POST['pass2']; checkOK($pass2); $email = $_POST['email']; checkOK($email); $email2 = $_POST['email2']; checkOK($email2); require('dbconfig.php'); // checks if the username is in use if (!get_magic_quotes_gpc()) { $user = addslashes($user); } $check = mysql_query("SELECT username FROM users WHERE username = '$user'") or die(mysql_error()); $check2 = mysql_num_rows($check); //if the name exists it gives an error if ($check2 = 0) { header("Location: register.php?reason=6"); //check that the variable's length is ok } else if ((strlen($user) < 5) && (strlen($user) > 20)) { //if the username is not the correct length, redirect header("location: register.php?reason=9"); } // this makes sure both passwords entered match if ($pass != $pass2) { header("Location: register.php?reason=7"); } // here we encrypt the password and add slashes if needed $pass = md5($pass); if (!get_magic_quotes_gpc()) { $pass = addslashes($pass); $user = addslashes($user); } // checks that both emails match if ($email != $email2) { header("Location: register.php?reason=8"); } //message subject $subject = "Social Space email verification"; //unique random string for boundary string $random_hash = randstr("md5"); //headers must be seperated with \r\n $headers = "From: no-reply@groupyournetworks.com\r\nReply-To: support@groupyournetworks.com"; //add boundary string and mime-type application $headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; //message body //generate random code with md5 encryption to ensure uniquity (mostly) $code = randstr("md5"); ob_start(); //Turn on output buffering ?> --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi <?php echo $user; ?> and welcome to Social Space. To complete your registration go to: http://www.groupyournetworks.com/authenticate.php?user=<?php echo $user; ?>&code=<?php echo $code; ?> --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit <h4>Hi <?php echo $user; ?></h4> <p>To complete your registration click the following link: <a href="http://www.groupyournetworks.com.authenticate.php?user=<?php echo $user; ?>&code=<?php echo $code; ?>"><?php echo $code; ?></a></p> --PHP-alt-<?php echo $random_hash; ?>-- <?php //save message to $message and clear output buffer $message = ob_get_clean(); if (mail($email, $subject, $message, $headers)) { } else { header("Location: register.php?reason=9"); } // now we insert it into the database $insert = "INSERT INTO users (username, password, email, new, valid, code) VALUES ('$user', '$pass', '$email', '1', '0', '$code')"; $insert2 = "INSERT INTO networks (ignore) VALUES ('ignore')"; $add_member = mysql_query($insert); $add_member2 = mysql_query($insert2); mysql_close(); header("Location: index.php?reason=5"); } else { die("The form must be submitted!"); } ?> Thanks, Jim
Create an account or sign in to comment