Well, I am getting moving on my site, finally got about all the main pages dynamically loading, and I have rand into a problem with my registration problem. I don't know what happened but I seem to be getting this strange error:
Fatal error: Cannot redeclare generatehash() (previously declared in /home/.../functions.inc.php:4) in /home/.../functions.inc.php on line 11
this is the beginning of my functions file:

<?php
	include 'dbconnect.php';

function generateHash($plainText, $salt = null) {//generate a secure password hash
	if ($salt === null) {//if no salt is present
		$salt = substr(md5(uniqid(rand(), true)), 0, 25);
		} else {
			$salt = substr($salt, 0, 25);
			}
	return $salt . sha1($salt . $plainText);
	}

The line that calls the function is line 78, so you don't have to search for it.

<?php
	session_start();
	include_once 'dbconnect.php';
	include_once 'functions.inc.php';

if (isset($_POST['submit'])) {

	$username = $_POST['username'];
	$email = $_POST['email'];
	$pass1 = $_POST['password'];
	$pass2 = $_POST['confirm'];

	$username = stripme($username);
	$email = stripme($email);
	$pass1 = stripme($pass1);
	$pass2 = stripme($pass2);

	require_once('recaptchalib.php');
		$privatekey = "*****************************";
		$resp = recaptcha_check_answer ($privatekey,
									$_SERVER["REMOTE_ADDR"],
									$_POST["recaptcha_challenge_field"],
									$_POST["recaptcha_response_field"]);

	if (!$resp->is_valid) {
	$errorMsg = "<li>Captcha must be entered correctly</li>";
	} else {//if the reCaptcha was correct!

		// Database duplicate username check setup for use below
			$unameCHecker = mysql_real_escape_string($username);
			$sql_uname_check = mysql_query("SELECT username FROM users WHERE username='$unameCHecker'"); 
			$uname_check = mysql_num_rows($sql_uname_check);
		// Database duplicate e-mail check setup for use below
			$emailCHecker = mysql_real_escape_string($email);
			$emailCHecker = str_replace("`", "", $emailCHecker);
			$sql_email_check = mysql_query("SELECT email FROM users WHERE email='$emailCHecker'");
			$email_check = mysql_num_rows($sql_email_check);
			$emailvalid = ValidEmail($email);

	if(!empty($username)) {
		if($uname_check > 0){ 
			$errorMsg .= "<li>Sorry, that username is already in our database</li>";
			}
		if((strlen($username) < 4) || (strlen($username) > 20)) {
			$errorMsg .= "<li>username must be betweeen 4-20 letters/numbers</li>";
			}
		} else {
			$errorMsg .= "<li>Please fill in your username</li>";
			}

	if(!empty($email)) {
		if($emailvalid) {
			if($email_check > 0){ 
				$errorMsg .= "<li>Sorry, that email address is already in our database</li>";
				}
			} else {
				$errorMsg .= "<li>Please provide a valid email address</li>";
				}
		} else {
			$errorMsg .= "<li>Please fill in your email address</li>";
			}

	if(!empty($pass1)) {
		if($pass1 != $pass2){ 
			$errorMsg .= "<li>both passwords must match</li>";
			}
		} else {
			$errorMsg .= "<li>Please fill in both password fields</li>";
			}

	if($errorMsg == "") { // Error handling is ended, process the data and add member to database

			$username = mysql_real_escape_string($username);
			$email = mysql_real_escape_string($email);
			$pass1 = mysql_real_escape_string($pass1);

			// Add infinite Hash to the password variable
			$db_password = generateHash($pass1);
			$db_date = time();
			$db_ip = $_SERVER['REMOTE_ADDR'];

			// Add user info into the database table for the main site table
			$sql = mysql_query("INSERT INTO users (regdate, username, email, password, regip) 
			VALUES('$db_date', '$username','$email','$db_password', '$db_ip')")  
			or die (mysql_error());
			$id = mysql_query("SELECT authorid FROM users WHERE username = $username");

	//!!!!!!!!!!!!!!!!!!!!!!!!!    Email User the activation link    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	$to = "$email";

	$from = 'noreply@zcomedy.com'; // $adminEmail is established in [ scripts/connect_to_mysql.php ]
	$subject = 'Complete Your ZComedy registration';
	//Begin HTML Email Message
	$message = "Hi $username,<br /><br />Click the link below to activate your account<br /><br />http://zcomedy.com/activation.php?id=$id&sequence=$db_password<br />If the URL above is not an active link, please copy and paste it into your browser address bar<br /><br />Login after successful activation using your:  <br />E-mail Address: $email <br />Password: chosen password<br /><br />See you on the site!";
	//end of message
	$headers  = "From: $from\r\n";
	$headers .= "Content-type: text/html";

	mail($to, $subject, $message, $headers);

	$msgToUser = "<div class=\"success\">Check your email for the activation link</div>";

	include_once 'sysmsg.php'; 
	exit();

		}// END member adding to database and email
		}//END successful captcha
		}//END if anything was submitted
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>Z Comedy</title>
	<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
	<div id="topbar">
		<a href="login.php">Login</a> | <a href="register.php">Register</a>
	</div>
	<div id="header">
		<a href="index.php"><img src="images/zcomedy.png" /></a>
	</div>
	<div id="container">
		<div id="sidebar">
			<?php main_menu() ?>
		</div>
		<div id="content">
			<h1>Register</h1>
			<?php
			if($errorMsg) {
			echo "<div class=\"error\">Error:<ul>";
			print $errorMsg;
			echo "</ul></div>";
						}
			?>
			<div class="joke">
			<script type="text/javascript">
 var RecaptchaOptions = {
    theme : 'clean'
 };
 </script>
				<form action="register.php" method="post">
					Desired Username:<br />
					<input type="text" name="username" value="<?php echo $_POST['username']; ?>" /><br />
					Email Address:<br />
					<input type="text" name="email" value="<?php echo $_POST['email']; ?>" /><br />
					Password<br />
					<input type="password" name="password" /><br />
					Confirm Password<br />
					<input type="password" name="confirm" /><br /><br />
					<?php
						require_once('recaptchalib.php');
						$publickey = "6LfUx8ESAAAAALmWGqgWuIzuOcNaCASNYXjWOlUg"; // you got this from the signup page
						echo recaptcha_get_html($publickey);
					?>
					<input type="submit" value="Register!" class="button" name="submit" />
				</form>
			</div>
		</div>
	</div>
</body>
</html>

You can test the code out for yourself at: http://epicrevolt.com/zcomedy/site/register.php

Recommended Answers

All 2 Replies

Don't post irrelevant code.
Try to pinpoint your problem.
Replace all include() by require_once().
// ardav, you out there? I was here already...

if($problem == "solved"){
  clickLink("mark_as_solved");
}

Yes, I got it fixed. It had to do with the require_once. After doing some research, I pinpointed the problem.

For anyone reading this post in search of help, make sure that if you are including a separate (external) functions file, make sure that you do require_once('functions.php'); or else the error will occur. do this on EVERY page that you call the functions.php, or else the Fatal Error will occur.

Why does te error occur? Because as listed on the code above, I am calling:

include_once 'sysmsg.php';

Which is the page it will load when the user successfully passes registration. If I did not do the require_once on top of both of those pages, the server will somehow recall the functions, which is a no no. :)

Thanks for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.