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:

[cc lang="php"]

$blacklist = array("122.456.789.55", "456.789.123.22", "789.123.45.26");

if(in_array($_SERVER['REMOTE_ADDR'], $blacklist)) {
	header("Location: http://www.php-examples.net/custom.php");
	exit();
}

[/cc]

Read More...

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:

[cc lang="php"]

if(@fsockopen($_SERVER['REMOTE_ADDR'], 80, $errstr, $errno, 1)) {
	die("Proxy access not allowed");
}

[/cc]

Read More...

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.

[cc lang="php"] downloadFile(“http://www.php-examples.net/xxx.mp3″); [/cc]

Read More...

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.

[cc lang="php"]

echo $remote_filesize("http://www.php-examples.net/xxx.txt");

[/cc]

Read More...

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.

[cc lang="php"]

echo distance(32.9697, -96.80322, 29.46786, -98.53506, "k")." kilometers";

[/cc]

Read More...

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.

[cc lang="php"]

$message = split_to_chunks(15,"Welcome to PHP Examples...");
print_r($message);

[/cc]

Read More...