SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Geek of all trades ... GORF's Avatar
    Join Date
    Oct 2004
    Location
    New England
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $HTTP_REFERER question

    I know I'm missing it

    $HTTP_REFERER returns http://www.domain.com/whatever.html.

    I need to pull just the domain or domain.com or www.domain.com out of the returned value of $HTTP_REFERER.

    I will be pulling the $HTTP_REFERER from other sites hosted in my reseller account on the same server.


    /too many weekend beers :apint:
    http://www.tonsofwebsites.com Hosting Tons of Websites for years
    http://www.cpanelbuys.com Buying cPanel hosting companies
    http://www.namesvibe.com Cheap domains - Good vibes!

  2. #2
    SitePoint Guru dbevfat's Avatar
    Join Date
    Dec 2004
    Location
    ljubljana, slovenia
    Posts
    684
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First, I'd suggest you don't use $HTTP_REFERER directly, since it is not available on servers with register_globals set to off. You can access it via $_SERVER['HTTP_REFERER'].

    Second, you must be careful when relying on the referer. You cannot trust that a browser will send it. Some proxies also remove this header from the request, so it is possible that your script won't work.

    And the answer to your question is http://www.php.net/parse_url.

    Regards.

  3. #3
    SitePoint Evangelist djdykes's Avatar
    Join Date
    Feb 2005
    Location
    Chester, Cheshire
    Posts
    565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    maybe $_SERVER['HTTP_HOST'] would be what your looking for....

    PHP Code:
    <?
    echo $_SERVER['HTTP_HOST'];
    ?>
    run locally this output localhost

  4. #4
    SitePoint Member
    Join Date
    Jun 2003
    Location
    Stuart, FL
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    split it into an array using "/", then split each segment that into an array using "." The first segment that retuns two or more segments will be your domain.

  5. #5
    Geek of all trades ... GORF's Avatar
    Join Date
    Oct 2004
    Location
    New England
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks everyone. I got what I needed.

    dirname($_SERVER[HTTP_REFERER]) works fine. It was easier than splitting the array.
    http://www.tonsofwebsites.com Hosting Tons of Websites for years
    http://www.cpanelbuys.com Buying cPanel hosting companies
    http://www.namesvibe.com Cheap domains - Good vibes!


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
  •