Read URL - PHP

Sharky Forums


Results 1 to 8 of 8

Thread: Read URL - PHP

  1. #1
    Ex-*** kid A's Avatar
    Join Date
    Sep 2000
    Location
    Norway
    Posts
    5,322

    Read URL - PHP

    Hey.

    Still very much a beginner, I want to make a little php snippet that does something like this:

    Code:
    if (currenturl = www.blablabla.com)
      goto blablabla.mysite.com
    I might be able to do some of it, but how to I find out what URL the viewer has typed in? (This site has two aliases which are in fact the exact same site)

    Thanks for any pointers!
    Now listening to various rock and metal
    143rd member to join Sharkyforums.

  2. #2
    Hammerhead Shark Tekime's Avatar
    Join Date
    Dec 2001
    Location
    Falmouth, ME
    Posts
    2,347
    PHP Code:
    $url $HTTP_SERVER_VARS["HTTP_HOST"] . $HTTP_SERVER_VARS["REQUEST_URI"]; 

    BTW The Pixies are great man, I think my fav was Where is my Mind. But it's been a while too
    Stuff and stuff

  3. #3
    Hammerhead Shark e_dawg's Avatar
    Join Date
    Jan 2001
    Location
    Earth, Western Hemisphere, North America, US, UT, SLC
    Posts
    2,628
    kid A, here's an idea...

    If they are on different machines or each URL directs to a different directory, forget the URL check and just do a header redirect like so:

    PHP Code:
    <?php header('Location: http://blablabla.mysite.com'); ?>
    I have a few sites that have just the above in an index.php to redirect to a page on that URL and some redirect from one URL to another using the same exact thing, just change the value of Location in the header.

    If they are in the same directory, your host could change the http server settings to do that or you could just use $HTTP_SERVER_VARS['HTTP_HOST'] (one of the variables Tekime pointed to) and do the logic on that, then run the code in the php block above.

    If you have a possibility of people trying to go to a location below that, append the request URI on the site name. I once did this on a site that was linked to from a number of places with many files in different directories that needed to be redirected to the new server.

  4. #4
    Ex-*** kid A's Avatar
    Join Date
    Sep 2000
    Location
    Norway
    Posts
    5,322
    You see, I only have one webspace, with two domain names pointing to it. That means they both end up in the exact same index page, I wanted to take one of the urls and redirect the visitor to a subdomain I have, but it seems my webhost won't actually allow this..
    Now listening to various rock and metal
    143rd member to join Sharkyforums.

  5. #5
    Hammerhead Shark e_dawg's Avatar
    Join Date
    Jan 2001
    Location
    Earth, Western Hemisphere, North America, US, UT, SLC
    Posts
    2,628
    Originally posted by kid A
    You see, I only have one webspace, with two domain names pointing to it. That means they both end up in the exact same index page, I wanted to take one of the urls and redirect the visitor to a subdomain I have, but it seems my webhost won't actually allow this..
    Put this at the very top of the index.php page:
    PHP Code:
    <?php
    if ($HTTP_SERVER_VARS['HTTP_HOST'] == 'www.blablabla.com')
    {
      
    header('Location: http://blablabla.mysite.com');
    }
    ?>

  6. #6
    Ex-*** kid A's Avatar
    Join Date
    Sep 2000
    Location
    Norway
    Posts
    5,322
    Most excellent Sir!

    I thank you.
    Now listening to various rock and metal
    143rd member to join Sharkyforums.

  7. #7
    Hammerhead Shark e_dawg's Avatar
    Join Date
    Jan 2001
    Location
    Earth, Western Hemisphere, North America, US, UT, SLC
    Posts
    2,628
    No problem.

    You could also do it in a single line by removing the '{' and '}' characters and putting the line inbetween them at the end of the if statement.

  8. #8
    Catfish m__'s Avatar
    Join Date
    Feb 2002
    Posts
    151

    If you're using Apache...

    Why not just use the .htaccess file to redirect. It's faster. Check out this tutorial:

    http://www.javascriptkit.com/howto/htaccess7.shtml

    Hope it helps.

    Oh yes and: Pixies. are. wonderful. River Euphrates = amazing.
    Last edited by m__; 09-04-2002 at 11:16 PM.
    Soyo Dragon Lite
    Athlon XP 2000+ (temporary crap fan & heat sink)
    512mb Mushkin PC2100
    Visiontek Xtasy GeForce3 Ti200 64mb
    80gig WD 7200rpm 8mb cache
    Lite On 32x12x40x CDRW (black)
    Lite On 16x DVD (black)
    Sound Blaster Audigy Platinum (black)
    Cambridge Soundworks DTT2200 5.1

Posting Permissions

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