PHP Page Redirect

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • snowdonkey
    New Member
    • Aug 2006
    • 37

    PHP Page Redirect

    Hey! How might I page redirect in PHP similar to how it might be done in JavaScript:

    window.onload = function Redirect()
    {
    window.location = "http://somesite.com";
    }

    Thanks
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    As follows:
    [php]header("Locatio n: http://somesite.com");[/php]
    Ronald :cool:

    Comment

    • snowdonkey
      New Member
      • Aug 2006
      • 37

      #3
      So simple! Thanks ronverdonk.

      Comment

      • snowdonkey
        New Member
        • Aug 2006
        • 37

        #4
        One more question, how do I get the current URL address of the page so that I can do something like, "If ocation = yahoo.com, then location = google.com?

        Comment

        • TheMadMidget
          New Member
          • Oct 2006
          • 98

          #5
          [PHP]
          $Location = $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING'];
          [/PHP]
          $_SERVER['HTTP_HOST'] is the domain and is in the direct form you asked.
          $_SERVER['PHP_SELF'] shows everything after the domain until a ? (if any)
          $_SERVER['QUERY_STRING'] show everything after the ? (if any)

          Comment

          • TheMadMidget
            New Member
            • Oct 2006
            • 98

            #6
            Also
            $_SERVER['REQUEST_URI'] is everything after the domain and is basically the combination of the PHP_SELF & ? & QUERY_STRING.

            Comment

            • snowdonkey
              New Member
              • Aug 2006
              • 37

              #7
              Exactly what I was looking for, thanks MadMidget.

              Comment

              Working...