Jump to content

Recommended Posts

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");
?>

Link to comment
https://forums.phpfreaks.com/topic/39025-solved-header-problem/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/39025-solved-header-problem/#findComment-187918
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/39025-solved-header-problem/#findComment-187945
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.