-2

my code in file signin.php says :

if(!$n==0) {        
    include 'home.html';
    header("location:home.html");
    exit();
}

But after i get redirected to home.html, the url still remains signin.php So when i refresh the page, signin.php file loads again. how do i make sure the url changes when the page is redirected. thank you in advance

kero
  • 10,647
  • 5
  • 41
  • 51
joyster
  • 21
  • 2
    It always does. This means you probably have another issue. I bet your redirect ins't happening because of headers being sent and you see home.html because you include it at the top of this file. – John Conde Jul 15 '14 at 13:25
  • you dont need to include the hmtl file in order to redirect to that page. – Chris Lam Jul 15 '14 at 13:26
  • im using form action php self so that my error messages are displayed on the same page. Is that why my header doesnt redirect? Are there any other methods to post errors on the same page signin.php and then if successful, redirect to home.html? – joyster Jul 15 '14 at 13:29

2 Answers2

0

You cannot successfully send and enact a redirect if there is any output sent back to the browser before the header() call. You should also immediately exit; after making the header call. If you have a session open, you should also close it with session_write_close() before making the header call. Consider using output buffering (i.e ob_start(),ob_end_clean(),etc.) to ensure that you can redirect at any point in your application without having to worry about the output issue.

You can also read a little more about how the PHP header function works:

http://php.net/manual/en/function.header.php

oliakaoil
  • 1,615
  • 2
  • 15
  • 36
0
Try this code:
header("Location: home.html");
Indrajeet Singh
  • 2,958
  • 25
  • 25