geudrik Posted August 3, 2009 Share Posted August 3, 2009 Well, Here's the error: Fatal error: Cannot redeclare database() (previously declared in /home/geudrik/spaazz.net/ahc/config.php:53) in /home/geudrik/spaazz.net/ahc/config.php on line 68 Here's the function within config.php... function database($option) { $dbuser = "xxxx"; $dbpass = "xxxx"; $dbname = "xxxx"; $dbhost = "xxxx"; if ($option = 'yes' || 'connect' || '1') { mysql_connect($dbhost, $dbuser, $dbpass) or die("There was an error connecting to the databse. <br> <b>Error:</b>".mysql_error()."<br><b>Error Num: </b>".mysql_errno().""); mysql_select_db($dbname) or die("There was an error connecting to the databse. <br> <b>Error:</b>".mysql_error()."<br><b>Error Num: </b>".mysql_errno().""); } else if ($option = 'no' || 'close' || '0') { mysql_close(); } else { die('General Database Fault in config.php Please go yell at Pat to fix the problem '); } } // lets close our function And here's the function that needs config.php included to use the database info... function new_user($username, $password, $passconf, $email, $passhint, $passhint_ans) { $isValid = true; $_SESSION['register_message'] = ''; include('./config.php'); //Checking to ensure that all fields are filled out... if (empty($username) || empty($password) || empty($passhint) || empty($passhint_ans) || empty($email) || empty($passconf)) { $_SESSION['register_message'] .= "There was an error processing your registration, most likely caused by a lack of information. Please ensure that all required fields are filled out."; $isValid = false; //Lets compare the passswords... Gotta make sure they match! } else if($password !== $passconf) { $_SESSION['register_message'] .= "The two passwords that you entered do not match. Please ensure that both passwords are identical"; $isValid = false; } // Checking to make sure that the username that is trying to be registered isn't already taken... [color=pink]database('1'); $checksql = "SELECT username FROM users WHERE username = '$username'"; if(!mysql_query($checksql)) { $_SESSION['register_message'] .= "The username you selected, '$username', is already taken. Please try a different one."; $isValid = false; } database('0');[/color] // Now hers a big chunk... Gotta make sure the email the user has entered works... $atIndex = strrpos($email, "@"); if (is_bool($atIndex) && !$atIndex) { $isValid = false; $_SESSION['register_message'] .= "There was an error with the email you supplied. Please try again."; } else { $domain = substr($email, $atIndex+1); $local = substr($email, 0, $atIndex); $localLen = strlen($local); $domainLen = strlen($domain); if ($localLen < 1 || $localLen > 64) { // local part length exceeded $isValid = false; $_SESSION['register_message'] .= "There was an error with the email you supplied. Please try again."; } else if ($domainLen < 1 || $domainLen > 255) { // domain part length exceeded $isValid = false; $_SESSION['register_message'] .= "There was an error with the email you supplied. Please try again."; } else if ($local[0] == '.' || $local[$localLen-1] == '.') { // local part starts or ends with '.' $isValid = false; $_SESSION['register_message'] .= "There was an error with the email you supplied. Please try again."; } else if (preg_match('/\\.\\./', $local)) { // local part has two consecutive dots $isValid = false; $_SESSION['register_message'] .= "There was an error with the email you supplied. Please try again."; } else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain)) { // character not valid in domain part $isValid = false; $_SESSION['register_message'] .= "There was an error with the email you supplied. Please try again."; } else if (preg_match('/\\.\\./', $domain)) { // domain part has two consecutive dots $isValid = false; $_SESSION['register_message'] .= "There was an error with the email you supplied. Please try again."; } else if(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) { // character not valid in local part unless // local part is quoted if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) { $isValid = false; $_SESSION['register_message'] .= "There was an error with the email you supplied. Please try again."; } } if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) { // domain not found in DNS $isValid = false; $_SESSION['register_message'] .= "There was an error with the email you supplied. Please try again."; } } //Now, if everything checks out.... lets do it! if($isValid == true) { include('./config.php'); $activationkey = md5($salt1.$username.$email); // Here, we're combining salt 1, username and email to be used as the encryption key $passwordenc = md5($salt2.$password.$salt1); // Here, we're using salt 1 and 2 to further the encryption of the password $sql = "INSERT INTO users(username, password, passhint, passhintans, email, seclevel, deactiveuser, activationkey) VALUES ( '$username', '$passwordenc', '$passhint', '$passhint_ans', '$email', '$seclevel', '$defaultinactive', '$activationkey' )"; database('yes'); // Open a connection to the database... See config.php for more info. mysql_query($sql) or die("There was an error registering you.<br><b>Error: </b>".mysql_error()."<br><b>Error Number: </b>".mysql_errno().""); database('no'); // Be sure to close our DB connection!! $emailbody = " Thank you $username for registering. Before you will be able to log in, you must complete the registration by clicking <a href=\"$siteroot/activate.php?username=$username&key=$activationkey&mode=auto\">here</a> or going to the URL listed below.<br> !!! <b>KEEP THIS EMAIL FOR YOUR RECORDS</b> !!!<br> Username: $username <br> Password: $password <br> Note: If you lose your password or forget it, you will have to go through the password recovery process. The reason for this is your own security. You password is NOT stored in our database in plain text. It's been encrypted for your protection - that means we are unable to retrieve it for you. <br><br> $siteroot/activate.php?username=$username&key=$activationkey&mode=auto <br><br> Alternativly, you can confirm your account manually by using the following information...<br> Username: $username<br> Key: $activationkey<br> and going to: $siteroot/activate.php and filling out the required fields.<br><br> Thank you for registering! If you have any questions, don't hesitate to get in touch with us.<br> $thanking "; mail($email, 'AHC Registration Confirmation', $emailbody, $headers); $_SESSION['register_message'] .= "$username has been successfully registered. Please check your email for the activation email."; return true; return $_SESSION['register_message']; } else if($isValid == false) { die("There were issues processing your request. <br>".$_SESSION['register_message'].""); } } //close the function ?> The above PINK code is something I'm trying - that is, I need to run a quick check to see if the username is already taken. If anyone has a quick solution to this, I'd love to see that too. The real reason for this post though is the error. I don't know where I'm going wrong / re-declaring the function. Help? Link to comment https://forums.phpfreaks.com/topic/168678-solved-redeclaring-function/ Share on other sites More sharing options...
geudrik Posted August 3, 2009 Author Share Posted August 3, 2009 In the second code box, about 3/4 of the way down, just after the email checking function was a second include for config.php Apparently, PHP doesn't like it when you include the file twice xD Link to comment https://forums.phpfreaks.com/topic/168678-solved-redeclaring-function/#findComment-889880 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.