proctk Posted February 18, 2007 Share Posted February 18, 2007 The part of the code that sends the email is giving a error because its sending a second header. Warning: Header may not contain more than a single header, new line detected. in /mnt/w0400/d11/s01/b02a5c57/www/etreasures.ca/Scripts/CodeChangePassword.php on line 50 I cannot figure out why this is happening. <?php session_start(); include ("../Connections/db.php"); $user_id = $_SESSION['user_id']; $email = $_SESSION['email_address']; $new_password = $_POST['new_password']; $confirm_password = $_POST['confirm_password']; if($new_password != $confirm_password){ $msg .= 'Passwords do not match.<br />'; urlencode($msg); header("Location: ../portal/editprofile.php?msg=$msg"); exit(); } if(($new_password =="")) { $msg .= 'Enter Password.<br />'; urlencode($msg); header("Location: ../portal/editprofile.php?msg=$msg"); exit(); } $db_password = md5($new_password); $sql = mysql_query("UPDATE members SET password='$db_password' WHERE user_id='$user_id'"); $subject = "You changed your password at Etreasures!"; $message = "Save this email as it contains the password that you selected. Not to worry your password has been encrypted to protect your privacy New Password: $new_password http://www.etreasures.ca Thanks! etreasures.ca This is an automated response, please do not reply!"; mail($email, $subject, $message, "From:eTreasures.ca <[email protected]>"); $msg = "Your Password has been changed. You will receive an email with your new password!"; urlencode($msg); header("Location: ../portal/editprofile.php?msg=$msg"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/39025-solved-header-problem/ Share on other sites More sharing options...
kenrbnsn Posted February 18, 2007 Share Posted February 18, 2007 Which is line 50? Ken Quote Link to comment https://forums.phpfreaks.com/topic/39025-solved-header-problem/#findComment-187905 Share on other sites More sharing options...
proctk Posted February 18, 2007 Author Share Posted February 18, 2007 the last header statement at the bottom Quote Link to comment https://forums.phpfreaks.com/topic/39025-solved-header-problem/#findComment-187913 Share on other sites More sharing options...
kenrbnsn Posted February 18, 2007 Share Posted February 18, 2007 You have a newline character in the middle of the value of the $msg variable. Put the value all on one line: <?php $msg = "Your Password has been changed. You will receive an email with your new password!"; header("Location: ../portal/editprofile.php?msg=" . urlencode($msg)); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/39025-solved-header-problem/#findComment-187918 Share on other sites More sharing options...
redarrow Posted February 18, 2007 Share Posted February 18, 2007 should work dont no? <?php $msg = "Your Password has been changed. You will receive an email with your new password!"; if($msg){ urlencode($msg); header("Location: ../portal/editprofile.php?msg=$msg"); exit; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/39025-solved-header-problem/#findComment-187920 Share on other sites More sharing options...
kenrbnsn Posted February 18, 2007 Share Posted February 18, 2007 Redarrow: That doesn't solve the OPs problem. Please refrain from posting answers without explanations, especially incorrect answers. Ken Quote Link to comment https://forums.phpfreaks.com/topic/39025-solved-header-problem/#findComment-187922 Share on other sites More sharing options...
wildteen88 Posted February 18, 2007 Share Posted February 18, 2007 Rather than send the message through the url, add the message to the session. Then when the has been redirected to new the page delete the temp session variable using unset after you have used the temp session variable. So this is your new code with this addition: <?php session_start(); include ("../Connections/db.php"); $user_id = $_SESSION['user_id']; $email = $_SESSION['email_address']; // always check user submitted data exists before using it. if( (isset($_POST['new_password']) && !empty($_POST['new_password'])) && (isset($_POST['confirm_password']) && !empty($_POST['confirm_password'])) ) { $new_password = $_POST['new_password']; $confirm_password = $_POST['confirm_password']; if($new_password != $confirm_password) { $_SESSION['temp_msg'] = 'Passwords do not match.<br />'; } else { $db_password = md5($new_password); $sql = mysql_query("UPDATE members SET password='$db_password' WHERE user_id='$user_id'"); $subject = "You changed your password at Etreasures!"; $message = "Save this email as it contains the password that you selected. Not to worry your password has been encrypted to protect your privacy New Password: $new_password http://www.etreasures.ca Thanks! etreasures.ca This is an automated response, please do not reply!"; mail($email, $subject, $message, "From: eTreasures.ca <[email protected]>"); $_SESSION['temp_msg'] = "Your Password has been changed. You will receive an email with your new password!"; } } else { $_SESSION['temp_msg'] = 'Please fill in all fields.<br />'; } header("Location: ../portal/editprofile.php"); ?> Now use $_SESSION['temp_msg'] to get the message rather than $_GET['msg'] in editprofile.php Quote Link to comment https://forums.phpfreaks.com/topic/39025-solved-header-problem/#findComment-187945 Share on other sites More sharing options...
proctk Posted February 19, 2007 Author Share Posted February 19, 2007 thank you for all the help problem is fixed Quote Link to comment https://forums.phpfreaks.com/topic/39025-solved-header-problem/#findComment-188310 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.