Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Dec 30, 2009 Dec 30, 2009

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!

TOPICS
Server side applications
2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Dec 30, 2009 Dec 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, s

...
Translate
LEGEND ,
Dec 30, 2009 Dec 30, 2009
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines