Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coding Help, Errors

Status
Not open for further replies.

Rhyan

Programmer
Jul 4, 2000
33
US

I'm getting these errors and not sure why, anyone have an idea?

Warning: Oops, php3_SetCookie called after header has been sent in /home/baaclub/baaclub- on line 15

Warning: Oops, php3_SetCookie called after header has been sent in /home/baaclub/baaclub- on line 16

Here's Confirm.php3

<?php

include($DOCUMENT_ROOT.'/include/database.php3');
include($DOCUMENT_ROOT.'/include/pre.php3');
include($DOCUMENT_ROOT.'/include/user.php3');



if ($hash && $email) {
$worked=user_confirm($hash,$email);
} else {
$feedback = '<H1>ERROR - Missing Params</H1>';
}

site_header('Account Confirmation');

if ($feedback) {
echo '<FONT COLOR=&quot;RED&quot;><H2>'.$feedback.'</H2></FONT>';
}

if (!$worked){
echo '<P><H1>Having Trouble Confirming?</H1>
<P>A change was just made to the system, try the
<A HREF=&quot;changeemail.php&quot;>Change Your Email Address</A>
page to receive a new confirmation email';
}
echo '<H3>Your BAA Private Community Account</H3>
<P>
<A HREF=&quot;login.php3&quot;>Login To BAA Private Community</A>
<P>
<A HREF=&quot;register.php3&quot;>Register A New Account</A>
<P>
<A HREF=&quot;changepass.php3&quot;>Change Your Password</A>';


site_footer();

?>

Heres the File user.php3

<?php
if (!defined (&quot;USER_PHP&quot;)){
define (&quot;USER_PHP&quot;, &quot;true&quot;);
$hidden_hash_var='your_password_here';
function user_set_tokens($user_name_in) {
global $SERVER_NAME;
global $hidden_hash_var,$user_name,$id_hash;
$feedback .= &quot;username=$user_name_in&quot;;
if (!$user_name_in) {
$feedback .= ' ERROR1 - User Name Missing When Setting Tokens ';
return false;
}
$user_name=strtolower($user_name_in);
$id_hash= md5($user_name.$hidden_hash_var);
setcookie('user_name',$user_name,(time()+25920),'/','',0);
setcookie('id_hash',$id_hash,(time()+25920),'/','',0);
}
$LOGGED_IN=false;
//clear it out in case someone sets it in the URL or something
unset($LOGGED_IN);
function user_isloggedin() {
global $user_name,$id_hash,$hidden_hash_var,$LOGGED_IN;
//have we already run the hash checks?
//If so, return the pre-set var
if (isset($LOGGED_IN)) {
return $LOGGED_IN;
}
if ($user_name && $id_hash) {
$hash=md5($user_name.$hidden_hash_var);
if ($hash == $id_hash) {
$LOGGED_IN=true;
return true;
} else {
$LOGGED_IN=false;
return false;
}
} else {
$LOGGED_IN=false;
return false;
}
}

function user_login($user_name,$password) {
global $feedback;
if (!$user_name || !$password) {
$feedback .= ' ERROR - Missing user name or password ';
return false;
} else {
$user_name=strtolower($user_name);
$password=strtolower($password);
$sql=&quot;SELECT * FROM user WHERE user_name='$user_name' AND password='&quot;. md5($password) .&quot;'&quot;;
$result=db_query($sql);
if (!$result || db_numrows($result) < 1){
$feedback .= ' ERROR - User not found or password incorrect ';
return false;
} else {
if (db_result($result,0,'is_confirmed') == '1') {
user_set_tokens($user_name);
$feedback .= ' SUCCESS1 - You Are Now Logged In ';
return true;
} else {
$feedback .= ' ERROR - You have not Confirmed Your Account Yet ';
return false;
}
}
}
}




function user_confirm($hash,$email) {
/*
Call this function on the user confirmation page,
which they arrive at when the click the link in the
account confirmation email
*/

global $feedback,$hidden_hash_var;

//verify that they did not tamper with the email address
$new_hash=md5($email.$hidden_hash_var);
if ($new_hash && ($new_hash==$hash)) {
//find this record in the db
$sql=&quot;SELECT * FROM user WHERE confirm_hash='$hash'&quot;;
$result=db_query($sql);
if (!$result || db_numrows($result) < 1) {
$feedback .= ' ERROR - Hash Not Found ';
return false;
} else {
//confirm the email and set account to active
$feedback .= ' User Account Updated - You Are Now Logged In ';
user_set_tokens(db_result($result,0,'user_name'));
$sql=&quot;UPDATE user SET email='$email',is_confirmed='1' WHERE confirm_hash='$hash'&quot;;
$result=db_query($sql);
return true;
}
} else {
$feedback .= ' HASH INVALID - UPDATE FAILED ';
return false;
}
}

function user_change_password ($new_password1,$new_password2,$change_user_name,$old_password) {
global $feedback;
//new passwords present and match?
if ($new_password1 && ($new_password1==$new_password2)) {
//is this password long enough?
if (account_pwvalid($new_password1)) {
//all vars are present?
if ($change_user_name && $old_password) {
//lower case everything
$change_user_name=strtolower($change_user_name);
$old_password=strtolower($old_password);
$new_password1=strtolower($new_password1);
$sql=&quot;SELECT * FROM user WHERE user_name='$change_user_name' AND password='&quot;. md5($old_password) .&quot;'&quot;;
$result=db_query($sql);
if (!$result || db_numrows($result) < 1) {
$feedback .= ' User not found or bad password '.db_error();
return false;
} else {
$sql=&quot;UPDATE user SET password='&quot;. md5($new_password1). &quot;' &quot;.
&quot;WHERE user_name='$change_user_name' AND password='&quot;. md5($old_password). &quot;'&quot;;
$result=db_query($sql);
if (!$result || db_affected_rows($result) < 1) {
$feedback .= ' NOTHING Changed '.db_error();
return false;
} else {
$feedback .= ' Password Changed ';
return true;
}
}
} else {
$feedback .= ' Must Provide User Name And Old Password ';
return false;
}
} else {
$feedback .= ' New Passwords Does not Meet Criteria ';
return false;
}
} else {
return false;
$feedback .= ' New Passwords Must Match ';
}
}

function user_lost_password ($email,$user_name) {
global $feedback,$hidden_hash_var;
if ($email && $user_name) {
$user_name=strtolower($user_name);
$sql=&quot;SELECT * FROM user WHERE user_name='$user_name' AND email='$email'&quot;;
$result=db_query($sql);
if (!$result || db_numrows($result) < 1) {
//no matching user found
$feedback .= ' ERROR - Incorrect User Name Or Email Address ';
return false;
} else {
//create a secure, new password
$new_pass=strtolower(substr(md5(time().$user_name.$hidden_hash_var),1,14));

//update the database to include the new password
$sql=&quot;UPDATE user SET password='&quot;. md5($new_pass) .&quot;' WHERE user_name='$user_name'&quot;;
$result=db_query($sql);

//send a simple email with the new password
mail ($email,'Password Reset','Your Password '.
'has been reset to: '.$new_pass,'From: pip@baaclub.com');
$feedback .= ' Your new password has been emailed to you. ';
return true;
}
} else {
$feedback .= ' ERROR - User Name and Email Address Are Required ';
return false;
}
}

function user_change_email ($password1,$new_email,$user_name) {
global $feedback,$hidden_hash_var;
if (validate_email($new_email)) {
$hash=md5($new_email.$hidden_hash_var);
//change the confirm hash in the db but not the email -
//send out a new confirm email with a new hash
$user_name=strtolower($user_name);
$password1=strtolower($password1);
$sql=&quot;UPDATE user SET confirm_hash='$hash' WHERE user_name='$user_name' AND password='&quot;. md5($password1) .&quot;'&quot;;
$result=db_query($sql);
if (!$result || db_affected_rows($result) < 1) {
$feedback .= ' ERROR - Incorrect User Name Or Password ';
return false;
} else {
$feedback .= ' Confirmation Sent ';
user_send_confirm_email($new_email,$hash);
return true;
}
} else {
$feedback .= ' New Email Address Appears Invalid ';
return false;
}
}

function user_send_confirm_email($email,$hash) {
/*
Used in the initial registration function
as well as the change email address function
*/

$message = &quot;Thank You For Registering For the BAA Private Community&quot;.
&quot;\nSimply follow this link to confirm your registration: &quot;.
&quot;\n\n urlencode($email).
&quot;\n\nOnce you confirm, you can use the services at BAA Private Community.&quot;;
mail ($email,'BAA Community Registration',$message,'From: Pip@baaclub.com');
}

function user_register($user_name,$password1,$password2,$email,$real_name) {
global $feedback,$hidden_hash_var;
//all vars present and passwords match?
if ($user_name && $password1 && $password1==$password2 && $email && validate_email($email)) {
//password and name are valid?
if (account_namevalid($user_name) && account_pwvalid($password1)) {
$user_name=strtolower($user_name);
$password1=strtolower($password1);

//does the name exist in the database?
$sql=&quot;SELECT * FROM user WHERE user_name='$user_name'&quot;;
$result=db_query($sql);
if ($result && db_numrows($result) > 0) {
$feedback .= ' ERROR - USER NAME EXISTS ';
return false;
} else {
//create a new hash to insert into the db and the confirmation email
$hash=md5($email.$hidden_hash_var);
$sql=&quot;INSERT INTO user (user_name,real_name,password,email,remote_addr,confirm_hash,is_confirmed) &quot;.
&quot;VALUES ('$user_name','$real_name','&quot;. md5($password1) .&quot;','$email','$GLOBALS[REMOTE_ADDR]','$hash','0')&quot;;
$result=db_query($sql);
if (!$result) {
$feedback .= ' ERROR - '.db_error();
return false;
} else {
//send the confirm email
user_send_confirm_email($email,$hash);
$feedback .= ' Successfully Registered. You Should Have a Confirmation Email Waiting ';
return true;
}
}
} else {
$feedback .= ' Account Name or Password Invalid ';
return false;
}
} else {
$feedback .= ' ERROR - Must Fill In User Name, Matching Passwords, And Provide Valid Email Address ';
return false;
}
}

function user_getid() {
global $G_USER_RESULT;
//see if we have already fetched this user from the db, if not, fetch it
if (!$G_USER_RESULT) {
$G_USER_RESULT=db_query(&quot;SELECT * FROM user WHERE user_name='&quot; . user_getname() . &quot;'&quot;);
}
if ($G_USER_RESULT && db_numrows($G_USER_RESULT) > 0) {
return db_result($G_USER_RESULT,0,'user_id');
} else {
return false;
}
}

function user_getrealname() {
global $G_USER_RESULT;
//see if we have already fetched this user from the db, if not, fetch it
if (!$G_USER_RESULT) {
$G_USER_RESULT=db_query(&quot;SELECT * FROM user WHERE user_name='&quot; . user_getname() . &quot;'&quot;);
}
if ($G_USER_RESULT && db_numrows($G_USER_RESULT) > 0) {
return db_result($G_USER_RESULT,0,'real_name');
} else {
return false;
}
}

function user_getemail() {
global $G_USER_RESULT;
//see if we have already fetched this user from the db, if not, fetch it
if (!$G_USER_RESULT) {
$G_USER_RESULT=db_query(&quot;SELECT * FROM user WHERE user_name='&quot; . user_getname() . &quot;'&quot;);
}
if ($G_USER_RESULT && db_numrows($G_USER_RESULT) > 0) {
return db_result($G_USER_RESULT,0,'email');
} else {
return false;
}
}

function user_getname() {
if (user_isloggedin()) {
return $GLOBALS['user_name'];
} else {
//look up the user some day when we need it
return ' ERROR - Not Logged In ';
}
}

function account_pwvalid($pw) {
global $feedback;
if (strlen($pw) < 6) {
$feedback .= &quot; Password must be at least 6 characters. &quot;;
return false;
}
return true;
}

function account_namevalid($name) {
global $feedback;
// no spaces
if (strrpos($name,' ') > 0) {
$feedback .= &quot; There cannot be any spaces in the login name. &quot;;
return false;
}

// must have at least one character
if (strspn($name,&quot;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;) == 0) {
$feedback .= &quot;There must be at least one character.&quot;;
return false;
}

// must contain all legal characters
if (strspn($name,&quot;abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_&quot;)
!= strlen($name)) {
$feedback .= &quot; Illegal character in name. &quot;;
return false;
}

// min and max length
if (strlen($name) < 5) {
$feedback .= &quot; Name is too short. It must be at least 5 characters. &quot;;
return false;
}
if (strlen($name) > 15) {
$feedback .= &quot;Name is too long. It must be less than 15 characters.&quot;;
return false;
}

// illegal names
if (eregi(&quot;^((root)|(bin)|(daemon)|(adm)|(lp)|(sync)|(shutdown)|(halt)|(mail)|(news)&quot;
. &quot;|(uucp)|(operator)|(games)|(mysql)|(httpd)|(nobody)|(dummy)&quot;
. &quot;|( {
$feedback .= &quot;Name is reserved.&quot;;
return 0;
}
if (eregi(&quot;^(anoncvs_)&quot;,$name)) {
$feedback .= &quot;Name is reserved for CVS.&quot;;
return false;
}

return true;
}

function validate_email ($address) {
return (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'. '@'. '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.' . '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $address));
}
}
?>
 
This is usually due to the fact that some text (html?) has already been output. Once that has happened you cannot send any HTTP headers - in your case cookie information. It looks like you may have auto_prepend_file set in your PHP initialisation file. Is that outputting a common page header or such like? In PHP4 there is an initialisation parameter called output_buffering which if set to On buffers the output before sending it, thus allowing headers to be sent even if html has been output. For PHP3 you may have to remove your auto_prepend_file setting and maybe call a function when you are *really* ready to output html.
 
Check your include files and make sure nothing
was send to the webserver ... not even blank lines
or spaces.

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top