PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hey I wanted to prevent people from leeching my bandwith. Last month I had 10GB of leeched traffic from 1 file. I found some code in the forum that kind of hid the file path but it's not exactly perfect.
<?php
if(IsSet($file))
{
header("location: ./path/$file");
}
else
{
echo "what do you want?";
}
?>
now people could copy that link and still link to it and not know the real path but still steal my bandwith. So i tried doing an http_referer in there but it always came up with the domain of my site when i tried running it from an html document locally. all the links are on my front page. my site is http://www.jaredindustries.com could someone edit this code or tell me what to do to prevent this from happening? below is what i tried to do it has the address of my site in there so you can see what i'm talking about
//check if a current session is in place and the user is correctly logged in
//also check the calling page / domain to ensure the call only comes from
//this domain -- this check may take a little configuration to get the
//correct host name, as it may be a virtual host with the webserver
//It's also possible, though more difficult to maintain, to use a list of all
//the possible pages in your site that access the db and check that list
//against the current calling page
if ($SESSION['logged_in'] != "some_value")&&($_SERVER['SERVER_NAME']!="my_host_name"){
echo "<span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> off, hackers!";
die();
}
so is that server name variable the name of the server this file was called from? my site doesn't require a login so i'm not sure about that first part.
You can still enable sessions, logins are not required, it would just help track users. Then simply check to see if you have an active session, maybe log the IP of the user and store that in a session.