Skip to main content
Known Participant
December 30, 2009
Answered

PHP - if go to one page, else go to another?!?

  • December 30, 2009
  • 1 reply
  • 2592 views

I have an if, else statement and I want to go to one page if and another page else.  I can't seem to get it to go the page.  It goes nowhere.  Can someone give me a sample php code how to do this?  Thanks!

This topic has been closed for replies.
Correct answer David_Powers

Rick4209 wrote:

I have an if, else statement and I want to go to one page if and another page else.  I can't seem to get it to go the page.  It goes nowhere.  Can someone give me a sample php code how to do this?  Thanks!

if (isset($_SESSION['MM_Username'])) {

  header ('Location: http://example.com/loggedin.php');

  exit;

} else {

  header ('Location: http://example.com/login.php');

  exit;

}

I suspect if you're going nowhere, it's because there is output before the call to header. For an explanation, see http://kb2.adobe.com/community/publishing/505/cpsid_50572.html.

1 reply

David_Powers
David_PowersCorrect answer
Inspiring
December 30, 2009

Rick4209 wrote:

I have an if, else statement and I want to go to one page if and another page else.  I can't seem to get it to go the page.  It goes nowhere.  Can someone give me a sample php code how to do this?  Thanks!

if (isset($_SESSION['MM_Username'])) {

  header ('Location: http://example.com/loggedin.php');

  exit;

} else {

  header ('Location: http://example.com/login.php');

  exit;

}

I suspect if you're going nowhere, it's because there is output before the call to header. For an explanation, see http://kb2.adobe.com/community/publishing/505/cpsid_50572.html.