Bryan K.
Bryan K.

Reputation: 165

Warning: Header may not contain more than a single header, new line detected

I have a question about PHP error. I went through other similar questions, and apply it, but I still have a problem like this, so I am asking it.

Situation is like this. There is an text box called special instruction; if I put just one line it is fine to work, but if I put more than one line it causes problem like this. I put urlencode(str) to solve the problem, but it is still showed up. What do I need to change? T.T

error message is "Warning: Header may not contain more than a single header, new line detected."

if($_POST['Submit'] == 'Submit Order'){
    $today = date('D M dY');
    $to_time = date('h:i a');
    $hours = substr($to_time, 0, -6);
    $minutes = substr($to_time, -5, 2);
    $seconds = substr($to_time, -2);
    $total_seconds = ($hours * 3600) + ($minutes * 60) + $seconds;

    $date123 = $_POST['day'];
    $date_post = date('D M dY',$date123);

    $time_post = $_POST['time']; 
    $hours_post   = substr($time_post, 0, -6);
    $minutes_post = substr($time_post, -5, 2);
    $seconds_post = substr($time_post, -2);
    $total_seconds_post = ($hours_post * 3600) + ($minutes_post * 60) + $seconds_post;

    $tip_amo = $_POST["tip_amount"];
    $deliv_mails = $_POST["deliv_mails"];
    $coupon_no = $_POST['coupon_no'];
    $minorder = $_POST['minorder'];
    $subtotal_amount = $_POST['subtotal_amount'];
    $payment_type = $_POST['payment_type'];
    $comments = addslashes($_POST['comments']);
    $coupon_code = $_REQUEST["coupon_code"];
    $customer_comments = get_field(CART,"additional_text","session_id='$sessionid'");

    if($comments == ''){
        $comments1 = $customer_comments;
    }else{
        $comments1 = $comments;
    }

    if($time_post!='') {
        if($today==$date_post){
            $query = [
                'day' => $date123,
                'time' => $time_post,
                'coupon_no' => $coupon_no,
                'minorder' => $minorder,
                'subtotal_amount' => $subtotal_amount,
                'payment_type' => $payment_type,
                'comments' => $comments1,
                'coupon_code' => $coupon_code,
                'tip_amount' => $tip_amo,
                'deliv_mails' => $deliv_mails,
                'd' => $address
            ];
            header('Location: details_info_order.php?' . http_build_query($query));
            exit;
        }else{
            $query = [
                'day' => $date123,
                'time' => $time_post,
                'coupon_no' => $coupon_no,
                'minorder' => $minorder,
                'subtotal_amount' => $subtotal_amount,
                'payment_type' => $payment_type,
                'comments' => $comments1,
                'coupon_code' => $coupon_code,
                'tip_amount' => $tip_amo,
                'deliv_mails' => $deliv_mails,
                'd' => $address
            ];
            header('Location: details_info_order.php?' . http_build_query($query));
            exit;
        }
    }
}

Warning: Header may not contain more than a single header, new line detected. in /home4/mikehan2/public_html/mikehan7/final_checkout_block.php on line 64

it is the exact error message.

Upvotes: 1

Views: 15348

Answers (2)

zakariae.dlimi
zakariae.dlimi

Reputation: 11

Some of your variables contains a multiline text, maybe COMMENTS. Use urlencode:

'comments' => urlencode($comments1),
...

Upvotes: 1

Phil
Phil

Reputation: 164897

You should really use something like http_build_query(); no need to manually URL encode and no messy string concatenation, eg

$query = array(
    'day' => $date123,
    'time' => $time_post,
    // etc
);
header('Location: details_info_order.php?' . http_build_query($query));
exit;

Upvotes: 8

Related Questions