Amran
Amran

Reputation: 657

New Line on PHP Header

How to insert String with new line on a header with php? Below are the codes that I did,

$error = "Not enough balance to submit. \nBalance available : " . $balance;
header('location:info-page.php?error=' . $error);

When I submit, it will give this error:

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

UPDATE CODES

$error = urlencode("Not enough balance to submit. \nBalance available : ". $baki_cuti);
header('location:permohonan_maklumat_penyelia.php?id='.$pid.'&error='. $error));

Page : permohonan_maklumat_penyelia.php

<?php
if (isset($_GET['error'])) {
    echo '<script type="text/javascript">
        alert("' .urldecode($_GET['error']) . '");
    </script>';
}
?>

Error received:

permohonan_maklumat_penyelia.php?id=842&error=Not+enough+balance+to+submit.+
Balance+available+%3A+0:112 Uncaught SyntaxError: Invalid or unexpected token

Upvotes: 1

Views: 1826

Answers (1)

flauntster
flauntster

Reputation: 2016

You could use urlencode to encode whatever string you like to be appended to the URL. And the receiving script could use urldecode to decode that string.

eg:

$error = urlencode("Not enough balance to submit. \nBalance available : $balance");

Hope this helps :)

Upvotes: 3

Related Questions