Zubrag.com
September 25, 2018, 11:10:27 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Set HTTP_REFERRER to recognize multiple domains?  (Read 12420 times)
timveer
Newbie
*
Posts: 4


« on: May 04, 2010, 07:40:08 PM »

Bravo! - the script is excellent. Completely "un-Microsoft" - simple, elegant and unbloated!!

One quick application question. I have two domains, one parked on top of the other. Depending how the user arrives at the site, the same domain is maintained for the visit. How can we modify the HTTP_REFERRER variable to allow downloads from more than one domain?

For example the domain is mydomain.com and yourdomain.com is parked on top of it. The download files and the php files are located on mydomain.com, but the script needs to work for either domain. I want to use the HTTP_REFERRER to prevent outside hotlinking.

Thanks for any suggestions.
Tim

Logged
zubrag
Administrator
Hero Member
*****
Posts: 788


WWW
« Reply #1 on: May 05, 2010, 01:00:27 AM »

I think comma or space separated will work. Like this   mydomain1.com,mydomain2.org
Logged
timveer
Newbie
*
Posts: 4


« Reply #2 on: April 14, 2011, 11:10:41 PM »

Hello Zubrag,

It has been a while since I used the script. I am again revisiting the need to have multiple Referrer domains.

I have tried your example and other variations without any luck. Do you or someone else have another idea to try?

This is what I tried. With some of the variations the first listed domain is allowed, but with other variations nothing is accepted.
define('ALLOWED_REFERRER', 'mydomain.com,yourdomain.com');
define('ALLOWED_REFERRER', 'mydomain.com','yourdomain.com');
define('ALLOWED_REFERRER', 'mydomain.com yourdomain.com');
define('ALLOWED_REFERRER', 'mydomain.com|yourdomain.com');

Thanks again for your simple and elegant solutions.
Tim
Logged
zubrag
Administrator
Hero Member
*****
Posts: 788


WWW
« Reply #3 on: April 15, 2011, 12:35:45 AM »

looks like i was wrong.

Try this. Put following code after DO NOT CHANGE section, so it will look like this (strpos_array function was copied from php.net)

Code:
####################################################################
###  DO NOT CHANGE BELOW
####################################################################

function strpos_array($haystack, $needles) {
    if ( is_array($needles) ) {
        foreach ($needles as $str) {
            if ( is_array($str) ) {
                $pos = strpos_array($haystack, $str);
            } else {
                $pos = strpos($haystack, strtoupper($str));
            }
        }
    } else {
        return strpos($haystack, strtoupper($needles));
    }
}

define your domains as follows (instead of define('ALLOWED_REFERRER'...) )
Code:
$ALLOWED_REFERRER = array('mydomain.com','yourdomain.net');

replace this:
Code:
strpos(strtoupper($_SERVER['HTTP_REFERER']),strtoupper(ALLOWED_REFERRER)) === false)
with this:
Code:
strpos_array(strtoupper($_SERVER['HTTP_REFERER']),$ALLOWED_REFERRER) === false)

and find all entries of text ALLOWED_REFERRER (there are 3 entries in the file) and make sure each of them have dollar $ before them (no spaces)



Logged
timveer
Newbie
*
Posts: 4


« Reply #4 on: April 15, 2011, 01:21:59 AM »

Zubrag,

That was fast Shocked

Thanks and I'll give it a try tomorrow. I'll come back to let you know how it works.

Cheers,
Tim
Logged
timveer
Newbie
*
Posts: 4


« Reply #5 on: April 19, 2011, 04:00:10 AM »

Hey Zubrag,

Still working on trying the multiple referrer suggestion you made - no time to play with it yet.

Tried the script as is and ran into a small problem (maybe something I changed?), the logging works fine, but it is recording two entries for every download. Any thoughts?

Thanks,
Tim
Logged
Paul
Newbie
*
Posts: 5


WWW
« Reply #6 on: April 21, 2011, 10:42:36 AM »

Tried the script as is and ran into a small problem (maybe something I changed?), the logging works fine, but it is recording two entries for every download. Any thoughts?

Coincidentally I decided to try out the logging today - not that I really need it, I was just curious, and I noticed it recorded double entries too, at first, but now it seems fine  Huh
Logged

[
Stev
Newbie
*
Posts: 2


« Reply #7 on: January 06, 2012, 01:45:54 AM »

Hi, love the script and need to allow various domains so I tried the example but get this error

Warning: Constants may only evaluate to scalar values in /home/xxxxx/public_html/download.php on line 19
Internal server error. Please contact system administrator.

On line 19 I have
define('ALLOWED_REFERRER', array('mydomain.com','yourdomain.net')); // except correct domains

And have added function strpos_array and updated
strpos_array(strtoupper($_SERVER['HTTP_REFERER']),ALLOWED_REFERRER) === false)

Any ideas?
Logged
zubrag
Administrator
Hero Member
*****
Posts: 788


WWW
« Reply #8 on: January 06, 2012, 02:31:59 AM »

Sorry that is because i did not try it first time. I fixed my post above, hope it is working, but had no chance to try.
Logged
Stev
Newbie
*
Posts: 2


« Reply #9 on: January 07, 2012, 08:04:00 PM »

That's fantastic, works a treat!

Many thanks,
Stev
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC