-1

I want to echo some html where the header is. I am new to coding and have tried to edit the code but have not had had any luck

if ($franchise_status == '0') {
    header('location:http://www.name.com/index.php');
}
} else {
    header('location:http://www.name.com/index.php');
}
halfer
  • 19,824
  • 17
  • 99
  • 186
  • you either echo or header; you can't do both. You'll be outputting before header if you place an echo above header, or use a meta refresh with echo; IF that's what the question is about here. – Funk Forty Niner Jun 08 '16 at 19:57
  • 3
    Your code is wrong, you have an extra `}`. – GrumpyCrouton Jun 08 '16 at 20:00
  • @GrumpyCrouton True; yet the question is about echoing with header; can't be done, not with a header – Funk Forty Niner Jun 08 '16 at 20:01
  • you can echo whatever you want **AFTER** the header has been output. any output peformed BEFORE the header() call will simply cause a 'headers already sent' error (ignoring things like the `ob` system). – Marc B Jun 08 '16 at 20:02
  • @MarcB you mean *"You can **use** echo after header"*, it just won't show up (with the header) ;-) – Funk Forty Niner Jun 08 '16 at 20:03
  • 2
    use such header `header('Refresh: 15; URL='.$url.');` and user will can read you html before redirect – splash58 Jun 08 '16 at 20:03
  • You should read up on understanding [headers](http://www.nicholassolutions.com/tutorials/php/headers.html#phpheaders) – GrumpyCrouton Jun 08 '16 at 20:07

2 Answers2

0

I am interpreting your question as if you want to remove the header and replace it with the HTML. If you want to echo HTML you simply have to write it like this:

echo "<p>paragraph</p>";

Do note that you can not do this before a header otherwise the header won't work.

yarwest
  • 873
  • 8
  • 19
0
  if($franchise_status == '0') {
     header('Location:http://www.name.com/index.php'); 
 } else { header('Location:http://www.name.com/index.php'); }

Your above code has been corrected. Header redirects you to another page so any php you echo after it would not show so you can do that before the header or save it as a session variable and then display it in the redirected page

e.g

  echo '<p>paragraph</p>';

Alternatively, you can echo, then sleep and redirect. Assuming you want the echo to run on same page.

Eg

  if($franchise_status == '0') {

   echo 'hey, blah blah';

   // sleep for a seconds
    sleep(5);

       //continue
  header('Location:http://www.name.com/index.php'); }
Mueyiwa Moses Ikomi
  • 1,069
  • 2
  • 12
  • 26