0

I have the problem in the header(). I know that it has to be before any html code, but with that to replace it so that it redirects to another url.

this is code (index.php):

<!DOCTYPE html>
<html lang="en">
<head>title</head>
<body>
<?php
$count = 1;
if ($count > 0) {
        header("Location:list.php?incluided");
    } else {
       header("Location:list.php?error");
    }
?>
<body>
<html>

How can I replace it?. Thanks.

The solution, add javascript and delete header():

<!DOCTYPE html>
<html lang="en">
<head>title</head>
<body>
<?php
$count = 1;
if ($count > 0) {
        print '
        <noscript>
          <meta http-equiv="refresh" content="0;>
        </noscript>
        <!--[if lt IE 9]><script type="text/javascript">var IE_fix=true;</script><![endif]-->
        <script type="text/javascript">
          if(typeof IE_fix != "undefined") // IE8 and lower fix to pass the http referer
          {
            document.write("redirecting...");
            var referLink = document.createElement("a");
            referLink.href = url;
            document.body.appendChild(referLink);
            referLink.click();
          }
          else { window.location.replace("list.php?incluided"); } // All other browsers
        </script>
        ';

    } else {

       print '
       <noscript>
         <meta http-equiv="refresh" content="0;>
       </noscript>
       <!--[if lt IE 9]><script type="text/javascript">var IE_fix=true;</script><![endif]-->
       <script type="text/javascript">
         if(typeof IE_fix != "undefined") // IE8 and lower fix to pass the http referer
         {
           document.write("redirecting...");
           var referLink = document.createElement("a");
           referLink.href = url;
           document.body.appendChild(referLink);
           referLink.click();
         }
         else { window.location.replace("list.php?error"); } // All other browsers
       </script>
       ';
    }
?>
<body>
<html>
A. M. Mérida
  • 2,458
  • 3
  • 18
  • 24

1 Answers1

2
<?php
$count = 1;
if ($count > 0)
    header("Location:list.php?incluided");
else
   header("Location:list.php?error");
die();
?>
<!DOCTYPE html>
<html lang="en">
<head>title</head>
<body>
<body>
<html>

Just put your redirection code on top.

Daniel Bürckner
  • 362
  • 1
  • 10