SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi everyone.

    i have this code:

    -----------------------------------
    index.php
    -----------------------------------
    <?php
    if($page == 1) {
    header("Location: /page1.php");
    }
    else {
    header("Location: /page2.php");
    }
    ?>
    -----------------------------------

    when i goto index.php?page=1, the address bar will look like this: "http://www.mysite.com/page1.php"
    my question is: is it possible to have the address bar display: "http://www.mysite.com/index.php?page=1" or page=2... all the time?

    Thank you

    Sang N.
    -------------------------------
    Send an E-card today!
    http://ecard.vinasite.com

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you really want it to, you could do this:
    <?php
    if($page == 1) {
    header("Location: /page1.php?page=".$page);
    }
    else {
    header("Location: /page2.php?page=".$page);
    }
    ?>

    By the way with regards to your post yesterday, what version of PHP is your host running?

    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    vinasite,

    A Location: header instructs the browser to fetch the specified document instead of the current one. As a result, the address bar will always change. The alternative is to load the redirected-to page within the current script, without telling the browser:

    Code:
    <?php
    if ($page == 1) {
      include("/path/to/page1.php");
      exit();
    } else {
      include("/path/to/page2.php");
      exit();
    }
    ?>
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2000
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Freddy,

    On one of my servers, i have php3, and on another, i have php4. The code you showed me worked with php4 but not with php3.




    Sang N.
    -------------------------------
    Send an E-card today!
    http://ecard.vinasite.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •