Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-06-2012, 06:13 PM   PM User | #1
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
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 10:33 PM..
durangod is offline   Reply With Quote
Old 10-06-2012, 07:23 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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"
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
durangod (10-06-2012)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:21 PM.


Advertisement
Log in to turn off these ads.