0

I have a button:

<form method="post">
<input name="submit" type="submit" class="icon2" value=" " />
</form>

And a redirect with a header using following code:

<?php
$homepage = '/2013/php/nelson-test.php';
$currentpage = $_SERVER['REQUEST_URI'];
if(isset($_POST['submit']) && $homepage==$currentpage)
{
header('Location:/2013/php/nelson.php');
}
?>

I used the exactly same code yesterday in a different site and it works (I only changed the links), and now it gives me this error:

Warning: Cannot modify header information - headers already sent by (output started at /homez.121/pneuexpo/www/2013/php/nelson-test.**php:1**) in /homez.121/pneuexpo/www/2013/php/nelson-test.php on **line 6**

I don't understand why since in line one I only have the php beginning tag and on line 6 there is only the header. Any ideas?

(BTW the purpose of the button and the header is that when you click the button it redirect to the same page but in English (the page is currently in French))

Michael Irigoyen
  • 22,513
  • 17
  • 89
  • 131
Alpha
  • 121
  • 1
  • 3
  • 10

5 Answers5

2

Remove ';' after this

if(isset($_POST['submit']) && $homepage==$currentpage)   //Remove ;
{
    header('Location:/2013/php/nelson.php');
    exit;
}
GautamD31
  • 28,552
  • 10
  • 64
  • 85
1

try this:

echo("<script>location.href = '/2013/php/nelson.php';</script>");
Jay
  • 3,353
  • 5
  • 25
  • 34
0

yes that is correct remove ; from it if you put ; then it interprete as a statement and it will raise error, and before header there should not be output on the page.

Sagar Rabadiya
  • 4,126
  • 1
  • 21
  • 27
0

as i am gussing your if condition is valid then please add exit

<?php
$homepage = '/2013/php/nelson-test.php';
$currentpage = $_SERVER['REQUEST_URI'];
if(isset($_POST['submit']) && $homepage==$currentpage);
{
header('Location:/2013/php/nelson.php');
exit;
}
?>
liyakat
  • 11,825
  • 2
  • 40
  • 46
0

remove all white space after

still if you cant remove error than redirect using javascript as follow

echo '<script type="text/javascript">window.location="nelson.php"</script>';
Sagar Rabadiya
  • 4,126
  • 1
  • 21
  • 27