-2

I am some reason having trouble with this, my header redirect does not seem to work.

<?php
   session_start();
   if(!session_is_registered(myusername)){
      header('Location:home.php');
      exit;
   }
?>

<html>
   <body>
      Login Successful
   </body>
</html>
iConnor
  • 19,997
  • 14
  • 62
  • 97

2 Answers2

0

Try this :

header("Location: home.php"); // there is a space
Mohamed Amine
  • 2,264
  • 1
  • 23
  • 36
  • Are you sure the condition is satisfied ? Try replacing your header by an echo "test"; to see if "test" is displayed... – Mohamed Amine Jul 28 '13 at 22:16
-1

Hmm, try

if(!isset($_SESSION['myusername'])){

instead of

if(!session_is_registered(myusername)){
Mohamed Amine
  • 2,264
  • 1
  • 23
  • 36
Kay
  • 797
  • 1
  • 6
  • 28
  • 1
    No, never get rid of exit; after a header to another page ! – Mohamed Amine Jul 28 '13 at 22:43
  • Can you explain? I've never used exit; when redirecting and never had any problems. – Kay Jul 28 '13 at 22:47
  • It's a security check ! It is recommended to use exit after a header to be sure that the code after isn't executed. The header redirects the user's browser to the new page, but the script is still being executed in the server side :) – Mohamed Amine Jul 28 '13 at 22:51
  • Ah, I see, thank you. I indeed never tried to run any other code after header redirects, which is probably why I did not (have to) use exit;. Will edit my reply if that's still possible? (I'm rather new to Stackoverflow...) -- Edit: Saw that an edit had been suggested and approved it! – Kay Jul 28 '13 at 22:54
  • Thanks, just approved it. :) – Kay Jul 28 '13 at 22:58