Block Multiple IP Addresses
Edit the following code with your blacklisted IPs and drop into the page or header file of your choice to enjoy immediate relief from relentless scumbags:
if(in_array($_SERVER['REMOTE_ADDR'], $blacklist)) {
header("Location: http://www.php-examples.net/custom.php");
exit();
}
Block Tough Proxies
To stop tough proxy visits from sites like hidemyass.com, add the following slice of finely crafted PHP to the top of your “header.php” file:
die("Proxy access not allowed");
}
Force file download
Some files, such as mp3, are generally played throught the client browser. If you prefer forcing download of such files, this is not a problem: The following code snippet will do that job properly.
Get remote filesize using cURL
Want to be able to calculate the size of a specific file? The following function can help. It takes 3 parameters: the file url, and in case the file is password protected, a username and a password.
Calculate distances in PHP
Here is a very handy function, which calculate the distance from a point A to a point B, using latitudes and longitudes. The function can return the distance in miles, kilometers, or nautical miles.
Split text up into 140 char array for Twitter
As you probably know, Twitter only accepts messages of 140 characters or less. If you want to interact with the popular social messaging site, you’ll enjoy this function for sure, which will allow you to truncate your message to 140 characters.
print_r($message);