headers already sent , ive tryed everything "

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
?>

Untitled Document <?php // show this error is the register process failed if(isset($insertError)){ echo $insertError;} ?>
<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]

<?php require("smtp.php"); require("sasl.php"); $from="[email protected]"; /* Change this to your address like "[email protected]"; */ $sender_line=__LINE__; $smtp=new smtp_class; $smtp->host_name="smtp.domain.co.uk"; //IP address /* Change this variable to the address of the SMTP server to relay, like "smtp.myisp.com" */ $smtp->host_port=25; /* Change this variable to the port of the SMTP server to use, like 465 */ $smtp->ssl=0; /* Change this variable if the SMTP server requires an secure connection using SSL */ $smtp->start_tls=0; /* Change this variable if the SMTP server requires security by starting TLS during the connection */ $smtp->localhost="my ip addr"; /* Your computer address */ $smtp->direct_delivery=0; /* Set to 1 to deliver directly to the recepient SMTP server */ $smtp->timeout=10; /* Set to the number of seconds wait for a successful connection to the SMTP server */ $smtp->data_timeout=0; /* Set to the number seconds wait for sending or retrieving data from the SMTP server. Set to 0 to use the same defined in the timeout variable */ $smtp->debug=1; /* Set to 1 to output the communication with the SMTP server */ $smtp->html_debug=1; /* Set to 1 to format the debug output as HTML */ $smtp->pop3_auth_host="domain.co.uk"; /* Set to the POP3 authentication host if your SMTP server requires prior POP3 authentication */ $smtp->user="[email protected]"; /* Set to the user name if the server requires authetication */ $smtp->realm=""; /* Set to the authetication realm, usually the authentication user e-mail domain */ $smtp->password="password"; /* Set to the authetication password */ $smtp->workstation=""; /* Workstation name for NTLM authentication */ $smtp->authentication_mechanism=""; /* Specify a SASL authentication method like LOGIN, PLAIN, CRAM-MD5, NTLM, etc.. Leave it empty to make the class negotiate if necessary */ $smtp->SendMessage( $from, array( $to ), array( "From: $from", "To: $to", "Subject: $subject", "Content-Type: text/html" ), "$message"); [/php]

one of the files you are including or requiring before you try to define your own header part, is sending something to the users browser.

ok thanks , if you have time could you have a quick scan over and see if anything catchs your eye, ive spent hours trying to work this out, Thanks ian

This is one of the includes

[php]
/*

  • sasl.php
  • @(#) $Id: sasl.php,v 1.11 2005/10/31 18:43:27 mlemos Exp $

*/

define(“SASL_INTERACT”, 2);
define(“SASL_CONTINUE”, 1);
define(“SASL_OK”, 0);
define(“SASL_FAIL”, -1);
define(“SASL_NOMECH”, -4);

class sasl_interact_class
{
var $id;
var $challenge;
var $prompt;
var $default_result;
var $result;
};

/*
{metadocument}<?xml version="1.0" encoding="ISO-8859-1" ?>

<package>net.manuellemos.sasl</package>

<version>@(#) $Id: sasl.php,v 1.11 2005/10/31 18:43:27 mlemos Exp $</version>
<copyright>Copyright © (C) Manuel Lemos 2004</copyright>
<title>Simple Authentication and Security Layer client</title>
<author>Manuel Lemos</author>
<authoraddress>mlemos-at-acm.org</authoraddress>

<documentation>
	<idiom>en</idiom>
	<purpose>Provide a common interface to plug-in driver classes that
		implement different mechanisms for authentication used by clients of
		standard protocols like SMTP, POP3, IMAP, HTTP, etc.. Currently the
		supported authentication mechanisms are: <tt>PLAIN</tt>,
		<tt>LOGIN</tt>, <tt>CRAM-MD5</tt>, <tt>Digest</tt> and <tt>NTML</tt>
		(Windows or Samba).</purpose>
	<usage>.</usage>
</documentation>

{/metadocument}
*/

class sasl_client_class
{
/* Public variables */

/*
{metadocument}

error
STRING


Store the message that is returned when an error
occurs.
Check this variable to understand what happened when a call to
any of the class functions has failed.
This class uses cumulative error handling. This means that if one
class functions that may fail is called and this variable was
already set to an error message due to a failure in a previous call
to the same or other function, the function will also fail and does
not do anything.
This allows programs using this class to safely call several
functions that may fail and only check the failure condition after
the last function call.
Just set this variable to an empty string to clear the error
condition.


{/metadocument}
*/
var $error=’’;

/*
{metadocument}

mechanism
STRING


Store the name of the mechanism that was selected during the
call to the Start function.
You can access this variable but do not change it.


{/metadocument}
*/
var $mechanism=’’;

/*
{metadocument}

encode_response
BOOLEAN
1

Let the drivers inform the applications whether responses
need to be encoded.
Applications should check this variable before sending
authentication responses to the server to determine if the
responses need to be encoded, eventually with base64 algorithm.


{/metadocument}
*/
var $encode_response=1;

/* Private variables */

var $driver;
var $drivers=array(
	"Digest"   => array("digest_sasl_client_class",   "digest_sasl_client.php"   ),
	"CRAM-MD5" => array("cram_md5_sasl_client_class", "cram_md5_sasl_client.php" ),
	"LOGIN"    => array("login_sasl_client_class",    "login_sasl_client.php"    ),
	"NTLM"     => array("ntlm_sasl_client_class",     "ntlm_sasl_client.php"     ),
	"PLAIN"    => array("plain_sasl_client_class",    "plain_sasl_client.php"    ),
	"Basic"    => array("basic_sasl_client_class",    "basic_sasl_client.php"    )
);
var $credentials=array();

/* Public functions */

/*
{metadocument}

SetCredential
VOID

Store the value of a credential that may be used by any of
the supported mechanisms to process the authentication messages and
responses.
Call this function before starting the authentication dialog
to pass all the credential values that be needed to use the type
of authentication that the applications may need.
.


key
STRING

Specify the name of the credential key.



value
STRING

Specify the value for the credential.



{/metadocument}
/
Function SetCredential($key,$value)
{
$this->credentials[$key]=$value;
}
/

{metadocument}


{/metadocument}
*/

/*
{metadocument}

GetCredentials
INTEGER

Retrieve the values of one or more credentials to be used by
the authentication mechanism classes.
This is meant to be used by authentication mechanism driver
classes to retrieve the credentials that may be neede.
The function may return SASL_CONTINUE if it
succeeded, or SASL_NOMECH if it was not possible to
retrieve one of the requested credentials.


credentials
HASH

Reference to an associative array variable with all the
credentials that are being requested. The function initializes
this associative array values.



defaults
HASH

Associative arrays with default values for credentials
that may have not been defined.



interactions
ARRAY

Not yet in use. It is meant to provide context
information to retrieve credentials that may be obtained
interacting with the user.



{/metadocument}
/
Function GetCredentials(&$credentials,$defaults,&$interactions)
{
Reset($credentials);
$end=(GetType($key=Key($credentials))!=“string”);
for(;!$end;)
{
if(!IsSet($this->credentials[$key]))
{
if(IsSet($defaults[$key]))
$credentials[$key]=$defaults[$key];
else
{
$this->error=“the requested credential “.$key.” is not defined”;
return(SASL_NOMECH);
}
}
else
$credentials[$key]=$this->credentials[$key];
Next($credentials);
$end=(GetType($key=Key($credentials))!=“string”);
}
return(SASL_CONTINUE);
}
/

{metadocument}


{/metadocument}
*/

/*
{metadocument}

Start
INTEGER

Process the initial authentication step initializing the
driver class that implements the first of the list of requested
mechanisms that is supported by this SASL client library
implementation.
Call this function specifying a list of mechanisms that the
server supports. If the
message
Start
argument returns a string, it should be sent to
the server as initial message. Check the
encode_response variable to determine
whether the initial message needs to be encoded, eventually with
base64 algorithm, before it is sent to the server.
The function may return SASL_CONTINUE if it
could start one of the requested authentication mechanisms. It
may return SASL_NOMECH if it was not possible to start
any of the requested mechanisms. It returns SASL_FAIL or
other value in case of error.


mechanisms
ARRAY


Define the list of names of authentication mechanisms
supported by the that should be tried.



message
STRING


Return the initial message that should be sent to the
server to start the authentication dialog. If this value is
undefined, no message should be sent to the server.



interactions
ARRAY

Not yet in use. It is meant to provide context
information to interact with the end user.



{/metadocument}
/
Function Start($mechanisms, &$message, &$interactions)
{
if(strlen($this->error))
return(SASL_FAIL);
if(IsSet($this->driver))
return($this->driver->Start($this,$message,$interactions));
$no_mechanism_error="";
for($m=0;$m<count($mechanisms);$m++)
{
$mechanism=$mechanisms[$m];
if(IsSet($this->drivers[$mechanism]))
{
if(!class_exists($this->drivers[$mechanism][0]))
require(dirname(FILE)."/".$this->drivers[$mechanism][1]);
$this->driver=new $this->drivers[$mechanism][0];
if($this->driver->Initialize($this))
{
$this->encode_response=1;
$status=$this->driver->Start($this,$message,$interactions);
switch($status)
{
case SASL_NOMECH:
Unset($this->driver);
if(strlen($no_mechanism_error)==0)
$no_mechanism_error=$this->error;
$this->error="";
break;
case SASL_CONTINUE:
$this->mechanism=$mechanism;
return($status);
default:
Unset($this->driver);
$this->error="";
return($status);
}
}
else
{
Unset($this->driver);
if(strlen($no_mechanism_error)==0)
$no_mechanism_error=$this->error;
$this->error="";
}
}
}
$this->error=(strlen($no_mechanism_error) ? $no_mechanism_error : “it was not requested any of the authentication mechanisms that are supported”);
return(SASL_NOMECH);
}
/

{metadocument}


{/metadocument}
*/

/*
{metadocument}

Step
INTEGER

Process the authentication steps after the initial step,
until the authetication iteration dialog is complete.
Call this function iteratively after a successful initial
step calling the Start function.
The function returns SASL_CONTINUE if step was
processed successfully, or returns SASL_FAIL in case of
error.


response
STRING


Pass the response returned by the server to the previous
step.



message
STRING


Return the message that should be sent to the server to
continue the authentication dialog. If this value is undefined,
no message should be sent to the server.



interactions
ARRAY

Not yet in use. It is meant to provide context
information to interact with the end user.



{/metadocument}
/
Function Step($response, &$message, &$interactions)
{
if(strlen($this->error))
return(SASL_FAIL);
return($this->driver->Step($this,$response,$message,$interactions));
}
/

{metadocument}


{/metadocument}
*/

};

/*

{metadocument}

{/metadocument}

*/

[/php]

The other script exceeds the char limit , is there any way to by pass the error at all ??

the script im using is found at http://www.9lessons.info/2011/07/send-mail-using-smtp-and-php.html

Sponsor our Newsletter | Privacy Policy | Terms of Service