how to open new page with php using if statment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kujtim
    New Member
    • Sep 2007
    • 11

    how to open new page with php using if statment

    i have problem openinng new pagee in my server by using php what i like is
    if the if statemant is true then open this page

    example:

    [code=php]
    if (x==0)
    {
    open page1.php
    }else
    {
    open page2.php
    }
    [/code]
    please help
    Last edited by Atli; Oct 5 '07, 03:21 AM. Reason: Fixed the [code] tags.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    What do you mean by 'open page'?

    If you only want to redirect the current page to somewhere else, you could us the header() function:
    [code=php]
    header("Locatio n: http://your.new.page/");
    [/code]

    If you want to open another window, you will have to use JavaScript:
    [code=php]
    echo "<script language=\"text/javascript\">wi ndow.open('http ://your.new.page/');</script>";
    [/code]

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, kujtim.

      Are you looking for include()?

      Comment

      • kujtim
        New Member
        • Sep 2007
        • 11

        #4
        what i mean is i gott this link
        [code=html]
        <a href="<? echo $_SERVER['PHP_SELF']; ?>?R=<? echo $my; ?>" style = "text-decoration:none ;".>
        [/code]
        with value R on itt what i want is when i click this link new page to opear , name of the page thet i want to open depend's on the value of R
        [code=php]
        if (R== 10 )
        {
        then open this page
        } else
        {
        open thet page
        }
        [/code]
        i have tryed using header but i am reciving this error :
        Code:
        Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\DzSoft\PHP Editor\php2CCA.tmp:9) in C:\Program Files\DzSoft\PHP Editor\php2CCA.tmp on line 11
        help
        Last edited by Atli; Oct 5 '07, 02:50 PM. Reason: Fixed the [code] tags.

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          The header() function will not work if you print anything to the page before you call it. This is because the header() function will attempt to modify the headers in the HTTP response, but once you start adding output the headers are locked.

          Try using the Output Control Functions if you can not avoid printing anything before calling the header() function.

          If that is not working for you, you could always cheat and use JavaScript:
          [code=php]
          echo "<script type='text/javascript'>loc ation.href='htt p://your.new.url/'</script>";
          [/code]
          But I would consider this a last resort, if all else fails. (Note, that not all clients will allow this!)

          Comment

          Working...