Squirrelington Posted December 27, 2002 Share Posted December 27, 2002 I sorta need help with this little line if ($ENV{HTTP_REFERER} =~ <regex here>) { i need to know the regex to make the equivelent of this * : / / w w w . n o t a r e a l s i t e . c o m * all my weird strings have failed, i tried everything based on the RegEx tutorials and non e worked, plz help Link to comment Share on other sites More sharing options...
0 Squirrelington Posted December 27, 2002 Author Share Posted December 27, 2002 sorry for the addr but if i don't show wehat its used for they might forget to gimme a code with escaped values and i dunno where i might need them all Link to comment Share on other sites More sharing options...
0 Quboid Posted December 27, 2002 Share Posted December 27, 2002 I don't understand what it is you want. Do you want to get the domain name (eg www.mydomain.com) from the HTTP_REFERER environment variable (eg http://www.mydomain.com/mydir/mypage.html)? Link to comment Share on other sites More sharing options...
0 Squirrelington Posted December 27, 2002 Author Share Posted December 27, 2002 like if the referer is from somewhere at www.notarealsite.com, then script executes, otherwize it dies. but yeah Link to comment Share on other sites More sharing options...
0 Squirrelington Posted December 27, 2002 Author Share Posted December 27, 2002 i am getting alot of music hotlinking off my site so i am moving the music to a hidden dir and the cgi script is gonna capture the music data and send it though it(song.cgi?songname) but i want it to do if the referer is not from my site, to stop processing, but if it is, to continue and send the music Link to comment Share on other sites More sharing options...
0 Tim Dorr Veteran Posted December 27, 2002 Veteran Share Posted December 27, 2002 there's a simpler way. just use Apache's mod_rewrite :) Put this in a .htaccess file in the same directory.. RewriteEngine ON RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://www.notasite.com/.*$ [NC] RewriteRule .*\.mp3$ - [F] Just change the site, and the extension to the right one (I'm assuming you're just concerned about mp3s here, and it will block users with a HTTP REFERER from a site not your own. Users without a referrer or with your site will be allowed in :) The basic regex you want though (assuming you still want to do it your way) shoud be like this: ^http://www.notasite.com/.* That *should* work just fine... Link to comment Share on other sites More sharing options...
0 Squirrelington Posted December 27, 2002 Author Share Posted December 27, 2002 i got a working regex as m / : \ / \ / w w w \ . n o t a s i t e \ . c o m \ / / and now i got a diff problem :p see other post i made Link to comment Share on other sites More sharing options...
Question
Squirrelington
I sorta need help with this little line
if ($ENV{HTTP_REFERER} =~ <regex here>) {
i need to know the regex to make the equivelent of this * : / / w w w . n o t a r e a l s i t e . c o m *
all my weird strings have failed, i tried everything based on the RegEx tutorials and non e worked, plz help
Link to comment
Share on other sites
6 answers to this question
Recommended Posts