Hi all , I have read all the other help snippets about the cannot modify headers and nothing is working , if someone has time can they have a look at my code and see if they spot anything i haven’t.
This register page emails using an smtp script( which i have download from another site and edited it , i will include these just in case they are needed.
The email sends and the database updates but the page stays on register.php and displays the header error.
register.php
[php]
session_start();
include(“scripts/connection.php”);// connect to the database
include(“includes/banned-passwords.php”);
// set variables blank to apend to
$emailError = “”;
$emailDup = “”;
$usernameError = “”;
$usernameDup = “”;
$secertError = “”;
$sqError = “”;
$passwordError = “”;
$passwordError2 ="" ;
$passMatchError = “”;
$password_banned = “”;
//check if the submit button has been pressed
if(isset($_POST[‘submit’]))
{
// set the variables from the form and make them safe for db
$username = mysql_real_escape_string(stripslashes($_POST[‘username’]));
$email = mysql_real_escape_string(stripslashes($_POST[‘email’]));
$password1 = mysql_real_escape_string(stripslashes($_POST[‘password1’]));
$password2 = mysql_real_escape_string(stripslashes($_POST[‘password2’]));
$newsletter = mysql_real_escape_string($_POST[‘newsletter’]);
if($newsletter != 1) // if the news letter isnt ticked set the value of it to 0
{
$newsletter = 0;
}
// check if the fields are filled in
if(strlen($username)<4) {$usernameError .= "Please enter a username";} // username must be over 4 chars long
if(strlen($email)< 5){$emailError .= "Please enter a email address";}// email must be over 5 chars long
if(strlen($password1)<6) {$passwordError .= "Please enter a password that is over 6 characters long";}// password must be over 4 chars in length
// check if the password is in the banned passwords list
if(in_array($password1, $banned_passwords))
{
$password_banned .= "This password is in our banned list , please pick a safter password";
}
if(empty($password2)) {$passwordError2 .= "Please re-type your password";}
// check if the passwords match
if($password1 != $password2)
{
$passMatchError .= " The passwords do not match , please retype your passwords.";
}
// check if the username is already being used
$checkUsername = mysql_query("SELECT `username` FROM general_user WHERE `username` = '$username'");
// get the number of results
$numResults = mysql_num_rows($checkUsername);
if($numResults == 1)
{
$usernameDup .=" The username '$username' is already in our system please enter a new username";
}
// check if email address is already in use
$emailCheck = mysql_query("SELECT `email` FROM general_user WHERE `email` = '$email'");
// get the number of results
$results = mysql_num_rows($emailCheck);
if($results == 1)
{
$emailDup .= "The email address '$email' is already is in our system , please enter a new email address";
}// results end
// if there are no errors set a the users salt and hash there password
if(empty($usernameError) && (empty($emailError) && (empty($passwordError) && (empty($passwordError2)
&& (empty($usernameDup) && (empty($passMatchError) && (empty($emailDup))))))))
{
$hash = hash("sha256",$password1);
$salt = sha1(rand());
$hashed_password = $salt . $hash;
// set the date joined
$date_joined = date("d-m-Y");
// generate a random activation code for the users email
$code = sha1(rand());
// set the standard account type
$type = "Standard";
// insert the users details into the database
$query = mysql_query("INSERT INTO general_user (username,hashed_password,email,salt,code,date_joined,newsletter,account_type)
VALUES
(’$username’,’$hashed_password’,’$email’,’$salt’,’$code’,’$date_joined’,’$newsletter’,’$type’)");
// if the query has worked
if($query)
{
// send email to the user the activation link with the code
$to = $email;
$subject = "Welcome todomain.co.uk ,please activate your acccount";
$message ='
Thank you '.$username.' for registering with domain.co.uk<br />
<br />
To start using your account please activate your account by clicking the link below<br />
<br />
<a href="http://www.domain.co.uk/activate.php?c='.$code.'">Click here to activate your account</a>
';
require_once("smtpwork.php");
header("Location: http://www.domain.com/welcome");
}else{
$insertError .= " Failed to register , please try again or contact [email protected] for help registering";
}
}
}// if submit is set end
?>
<form action="<?php $_SERVER['PHP_SELF'];?>" method="post">
<?php if(isset($usernameError)){echo $usernameError;} // show this error if the field is empty or doesnt match preg_match
if(isset($usernameDup)) {echo $usernameDup;}// show this error if the username is already used
?>
<div>
Username <input type="text" name="username" value="<?php echo $_POST['username'];?>"/>
</div>
<?php if(isset($emailError)){echo $emailError;}// show this error if the field is empty or doesnt meet strlen
if(isset($emailDup)) {echo $emailDup;}// show this error if the email address is already in use
?>
<div>
Email <input type="text" name="email" value="<?php echo $_POST['email'];?>"/>
</div>
<?php if(isset($passwordError)){ echo $passwordError;} // show this error is the password is empty or doesnt match strlen
if(isset($passMatchError)){echo $passMatchError;}// show the error if the passwords do not match
?>
<div>
Password <input type="password" name="password1" value="<?php echo $_POST['password1'];?>" />
</div>
<?php
if(isset($passwordError2)){ echo $passwordError2 ;}// show this error is the password re-type is empty
if(isset($password_banned)){ echo "<br />". $password_banned;}// display error if password is in banned list }
?>
<div>
Re-type Password <input type="password" name="password2" value="<?php echo $_POST['password2'];?>" />
</div>
<div>
Newsletter<input type="checkbox" name="newsletter" value="1" checked="checked" />
</div>
<div><input type="submit" name="submit" value="Register" /></div>
</form>
[/php]
The first part of the smtp mailer
[php]