Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: referer array

  1. #1
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,452
    Thanks
    275
    Thanked 32 Times in 31 Posts

    referer array

    Question, im trying to grab just the root of HTTP_REFERER.

    The below will work but sometimes RERERER is like this

    And of course in that case the key exist will be false. So whats the best way to limit REFERER to just root.

    PHP Code:
    $ref $_SERVER['HTTP_REFERER'];

    $ok_array = array('http://www.mysite.com''www.mysitel.com''mysite.com');
     
    if (
    array_key_exists($ref$ok)) 
    {
      
    //do something 

    I do understand that REFERER could be blank for non referrers but that will be fine, i am trying to hardcode just my site as permitted, the rest can do what they want.

    i guess i could use SERVER_NAME right

    Thanks.
    Last edited by durangod; 10-06-2012 at 11:33 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    No, server name will be your server.
    You want to use parse_url():
    PHP Code:
    if (!empty($ref))
    {
        
    $domain parse_url($refPHP_URL_DOMAIN);
        
    in_array($domain$ok_array))
        {
            
    // its in the array
        
    }

    so with your example, that would create $domain with the value of "www.mysite.com"

  • Users who have thanked Fou-Lu for this post:

    durangod (10-06-2012)


  •  

    Posting Permissions

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