Jump to content

Recommended Posts

Okay so I'm optimizing my registration script (condensing from two files to one basically) and though it works as two files, when I put them into one it outputs this funny error:

Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 77824 bytes) in /home/peachsi/public_html/xuthonia/register.php on line 89

 

But the thing is I never got that error when I had the two files separate and I'm not doing anything huge.  Line 90 is a simple mysql_query that isn't very large.  Here's the query

$sql = mysql_query("INSERT INTO users (username, encryptpass, password, email, name, gender, signup) VALUES('$username','$db_password','$rpassw0rd','$email','$name','$gender',now())") or die (mysql_error()); 

 

And here's the part of the code that gets executed if the register form has been submitted

$junk = array('.', ',', '/', '`', ';' , '[' ,  ']' , '-', '*', '&', '^', '%', '$', '#', '@', '!', '~', '+', '(', ')', '|', '{', '}', '<', '>', '?', ':', '"', '=', '\''); 
		  
  //starting lenght of username
  $len = strlen($_POST['username']);
  $len2 = strlen($_POST['password']);
  
  //replace invalid characters
  $_POST['username'] = str_replace($junk, '', $_POST['username']);
  $test = $_POST['username'];
  $_POST['password'] = str_replace($junk, '', $_POST['password']);
  $test2 = $_POST['password'];
  
  //if lenghts are different ($len smaller), invalid characters found, so prompt error.
  if(strlen($test) != $len) {
     die('Username Error: Username contained invalid characters. You can only use A-Z, 0-9 and the 

underscore (_).'); }
  elseif(strlen($test2) != $len2) {
     die('Username Error: Password contained invalid characters. You can only use A-Z, 0-9 and the 

underscore (_).'); }
  else {
$username = mysql_real_escape_string(stripslashes($_POST['username']));
$rpassw0rd = mysql_real_escape_string(stripslashes($_POST['password']));
$passwordck = stripslashes($_POST['passwordck']);
$email = mysql_real_escape_string(stripslashes($_POST['contact']));
$ckemail = mysql_real_escape_string(stripslashes($_POST['ckemail']));
$name = stripslashes($_POST['name']);
$gender=$_POST['gender'];
$birthday=$_POST['day'];
$birthmonth=$_POST['month'];
$birthyear=$_POST['year'];
$code=$_POST['code'];
//check if the required fields are filled in
if ((!$username) || (!$email) || (!$ckemail) || (!$name) || (!$rpassw0rd) || (!$passwordck) || (!$code)){
        $error="You missed a required field!";
        include('register.php');
	  exit();}
	  elseif ($passwordck != $rpassw0rd){
			$error="Your passwords don't match!";
			include('register.php');
			exit();
			}
        elseif ($email != $ckemail){//If the email addresses dont match
			$error="Your email addresses don't match"; //Show error message
                include('register.php');
                	}
	  elseif($code!='pineapple'){
			$error="You don't have the right signup code!";
			include('register.php');
					  exit();
					  }
	  else { //if everything checks out connect to the database!
                                //figure out if the username's already being used
			$q2 = mysql_query("SELECT username FROM users WHERE username='$username'") or die(mysql_error());
			$q3 = mysql_num_rows($q2);
			$q4 = mysql_query("SELECT email FROM users WHERE email='$email'") or die(mysql_error());
			$q5 = mysql_num_rows($q4);
			if($q3!=0) {
				 $error="Sorry, but that username has already been taken by another user.  Please choose another.";
				 include('register.php');
			exit();
}
                        
	  elseif($q5!=0) {
			$error="There is already an account created with that email address.";
			include ('register.php');
			exit();
}
	  elseif(!checkdate($birthmonth, $birthday, $birthyear)){
			$error="The birthday you entered is not a valid date";
			include('register.php');
			exit();
			}
	  else { $codebase=sha1($username);
			$activecode=substr($codebase,0,9);
			$db_password = md5($rpassw0rd); 
			// Enter info into the Database.
			$sql = mysql_query("INSERT INTO users (username, encryptpass, password, email, name, gender, signup) VALUES('$username','$db_password','$rpassw0rd','$email','$name','$gender',now())") or die (mysql_error()); 
			if(!$sql){ 
				 echo 'There has been an error creating your account. Please contact the webmaster.'; 
			} else { 
				 // Let's mail the user! 
				 $subject = "Your Membership at Xuthonia!"; 
				 $message = "Dear $name, 
				 Thank you for registering at our website, http://xuthonia.net!

				 Your activation code is: $activecode

				 To activate your membership, please click here: http://v1.xuthonia.net/activate.php?code=$activecode
				 Once you activate your memebership, you will be able to login 

				 Thanks! 
												 Xuthonia Admins 
				 This is an automated response, please do not reply!";  
				 $sendemail = mail($email, $subject, $message,  
					  "From: Administration<admin@xuthonia.net>\n 
					  X-Mailer: PHP/" . phpversion()); 
				 if(!$sendemail) { print 'There was an error setting up your account.';
											}
			else {print'Your membership information has been mailed to your email address! 
				 Please check it and follow the directions!'; }
} 

}

}
}

 

I've run this code before and never has it gotten an error until now.  If it helps, I had this huge session error before that just went on (forever it seemed)...but that's gone now so I don't understand why I'm still getting this.

 

Any help would be greatly appreciated =)

Link to comment
https://forums.phpfreaks.com/topic/87924-solved-getting-an-odd-fatal-error/
Share on other sites

Thanks...but that doesn't do anything.  There's around 200 lines of code in the entire file.  I've written bigger scripts with more queries that have worked fine.

 

And when I increase the memory size just to make sure that the code works, it still outputs the error.  I have it set to 30M right now, and nothing changes.  This tells to me that there's some sort of error somewhere else that is doing something wrong.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.