Help - Search - Members - Calendar
Full Version: Save Tons Of Bandwidth On Your Proxy Site
Pixel2Life Forum > Member Tutorials and Requests > Forum Tutorial Archives > PHP Tutorials
proxinated
Ok in the main index.php of your site insert this right after the "<?php" tag to save loads of bandwidth.

$domain="proxywebsite.com"; // insert your domain name here, NO www.!!!
$referer=$_SERVER['HTTP_REFERER'];
$count=substr_count($referer,$domain);
if($referer!="" && $count==0){
if($HTTP_GET_VARS['q']!="" && $HTTP_GET_VARS['hl']==""){
header("Location: http://" . $domain . "/");
exit();
}
}

The code checks to see if there is only an object (image, swf etc) being requested by a referer that is not your site. If it finds that an only an object is being requested, and no html, it will redirect straight to the homepage of your site. This prevents any files being hotlinked!
Ben
Thankyou for sharing this! Ive been hosting a private proxy server for school, but word got out and now everyones using it. I did have a problem with bandwidth. So thanks =D
Indigo
I still donīt quite get how this will save me lots of bandwidth, can you explain?
And you say that if only an image is requested, it will redirect the user to my index again. Do you then mean that if I insert this code in my index.php, and somebody try to access the folder "damdidam/myimage.jpg", they will be redirected to index.php?

Iīm such a noob ph34r.gif
Hayden
QUOTE(proxinated @ May 15 2006, 03:43 AM) *
Ok in the main index.php of your site insert this right after the "<?php" tag to save loads of bandwidth.

$domain="proxywebsite.com"; // insert your domain name here, NO www.!!!
$referer=$_SERVER['HTTP_REFERER'];
$count=substr_count($referer,$domain);
if($referer!="" && $count==0){
if($HTTP_GET_VARS['q']!="" && $HTTP_GET_VARS['hl']==""){
header("Location: http://" . $domain . "/");
exit();
}
}

The code checks to see if there is only an object (image, swf etc) being requested by a referer that is not your site. If it finds that an only an object is being requested, and no html, it will redirect straight to the homepage of your site. This prevents any files being hotlinked!


How would this differ from doing it in .htaccess?

CODE
RewriteEngine    on
RewriteCond    %{HTTP_REFERER} !^$
RewriteCond    %{HTTP_REFERER} !^http://([-a-z0-9]+\.)?dorkytutorial\.com [NC]
RewriteRule    \.(gif|jpe?g|png)$ - [F,NC,L]
Jordan Pittman
.htaccess is better, because the requests would have to be going through the index.php page on the code he/she gave
Lewisthemusician
Thanks, i needed this, i use free hosting with like hardly any bandwidth so this would be handy.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.