Saturday, June 21, 2008
Wednesday, June 18, 2008
Bandwidth Test, Speed Test
<?php
/*** Bandwidth Tester 0.92 ***/
/* Please wait for 1.0 patiently! */
// How many bytes to test with. Mimimum=70. 128KB=131072. 1MB=1048576
$testsize = 1048576;
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// always modified
header ("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header ("Pragma: no-cache"); // HTTP/1.0
header ("X-Notice: ");
header ("X-Notice: Bandwidth-Tester is freeware.");
header ("X-Notice: You may use it freely on your site.");
header ("X-Notice: Just don't remove this notice.");
header ("X-Notice: To get the source code, run this script ");
header ("X-Notice: with downloadme=1 in the query string.");
/* How does it work? The script generates a variable amount of random data
* sends it to the client and measures the time taken for transmission. The
* bandwidth is then calculated from the time using a simple algorithm.
*
* WARNING: This script can bog down your server - as absolutely NO
* optimization was used.
*
*
* This script is best run on the Zend PHP Engine, with Zend Optimizer.
* Any improvement in performance is not guaranteed with other
* PHP Engines.
*
* History:
* 0.9 - First public release
* 0.91 - Reduced the size of the timing code
* 0.92 - Reduced the size of the timing code even more
* Forecast:
* 0.921a - Adding a smaller test before the main to make results more accurate and to adjust test data according to first results
* 1.0 - Looking to adding optimization code
* 1.1 - Adding template support
* 1.2 - Adding web-based administration
*/
if($downloadme==1){
echo "<html><body>";
show_source($SCRIPT_FILENAME);
echo "</body></html>";
}
else {
// First, initialize the test comment
// seed random
srand ((double) microtime() * 1000000);
if($testsize<70) {die("<script>alert('The test string size is less than 70. Cannot test.')</script>");
}
$realtestsize = $testsize - 70;
function GetTestString($drealtestsize){
$duhteststring = "<!"."--";
for($i=0;$i<$drealtestsize; $i++){
$duhteststring .= generatekeycode();
}
$duhteststring .= "-"."->";
return $duhteststring;
}
function CalculateBandwidth($Ditt,$Dott){
$Datasize=$Dott;
$LS=$Datasize/$Ditt;
$kbps=(($LS*8)*10*1.02)/10;
$mbps=$kbps/1024;
if($mbps>=1){$speed=$mbps." Mbps aka ".$kbps." Kbps";}
else {$speed=$kbps." Kbps aka ".$mbps." Mbps";}
$speed .="<br>Time taken to test connection: ".(($Ditt*1024)/1000)." Seconds <br>A number used to determine your speed: ".$LS."<br>Another number used to determine your speed: ".$Ditt."<br>Tested your connection with ".$Datasize."Bytes/".($Datasize/1024)."KB/".($Datasize/1048576)."MB of random data<br>";
return $speed;
}
function generatekeycode(){
// srand ((double) microtime() * 1000000);
// Made the randomizer a little more "random"! :)
srand ((double) microtime() * rand(100000,1000000) / rand(1,15));
$tester = rand(33,255);
if($tester==45)return generatekeycode();
return chr($tester);
}
?><html>
<head><title>Bandwidth Tester</title></head>
<body><?php
if($HTTP_SERVER_VARS["REQUEST_METHOD"]=="GET" && $HTTP_GET_VARS["execute"]!="1"){
echo('<form action="'.$HTTP_SERVER_VARS["SCRIPT_NAME"].'" method="GET">
<input type="submit" value="Click Here To Begin Testing" onClick="this.value="Please wait while your request is being processed, it may take a while">
<input type="hidden" name="execute" value="1">
<input type="hidden" name="DO.NOT.CACHE" value="'.rand(255,65536).'">
</form>');}
elseif($HTTP_GET_VARS["execute"]=="1"){
$teststring=GetTestString($realtestsize);echo('<form method="POST" action="'.$HTTP_SERVER_VARS["SCRIPT_NAME"].'">
<input type="hidden" name="td" value="No Test">
<input type="button" value="Please wait while your request is being processed, it may take a while">
</form>
<script language="JavaScript">
var Hi = new Date();
</script>'.$teststring.'<script language="JavaScript">
var Bye = new Date();
var NiHao = new Array(Hi.getTime(),Bye.getTime());
var Factor=1024;
if(NiHao[1]==NiHao[0])
Ditt=0;
else
Ditt=(NiHao[1]-NiHao[0])/Factor;
document.forms[0].elements[0].value=Ditt;
document.forms[0].submit();
</script><p>Tested. Now processing your request....</p>');}
elseif($HTTP_SERVER_VARS["REQUEST_METHOD"]=="POST"&&$HTTP_POST_VARS["td"]>0){
echo('<p>We have tested your Internet connection.<br>
The speed to which you connected to us is '.CalculateBandwidth($HTTP_POST_VARS["td"],$testsize).'
Thank you!<br>
</p>');}
elseif($HTTP_SERVER_VARS["REQUEST_METHOD"]=="POST"&&$HTTP_POST_VARS["td"]==0){
echo('<p>We were unable to test your connection speed.<br>It was too fast to measure.<br>
<a href="'.$HTTP_SERVER_VARS["SCRIPT_NAME"].'?execute=1&DO.NOT.CACHE='.rand(255,65536).'" onClick="this.innerText=\'The system is now generating the random test data to benchmark your connection speed. It will take a while.\'">If you would like to try testing again, click here.</a></p>
<p>'.CalculateBandwidth($HTTP_POST_VARS["td"],$testsize).'</p>');
}
?>
</body>
</html><?php } ?>
http://www.yourip.zxq.net
Number of days between two dates
<?php
// Set the default timezone to US/Eastern
date_default_timezone_set('US/Eastern');
// Will return the number of days between the two dates passed in
function count_days($a, $b) {
// First we need to break these dates into their constituent parts:
$a_parts = getdate($a);
$b_parts = getdate($b);
// Now recreate these timestamps, based upon noon on each day
// The specific time doesn't matter but it must be the same each day
$a_new = mktime(12, 0, 0, $a_dt['mon'], $a_dt['mday'], $a_dt['year']);
$b_new = mktime(12, 0, 0, $b_dt['mon'], $b_dt['mday'], $b_dt['year']);
// Subtract these two numbers and divide by the number of seconds in a
// day. Round the result since crossing over a daylight savings time
// barrier will cause this time to be off by an hour or two.
return round(abs($a_new - $b_new) / 86400);
}
// Prepare a few dates
$date1 = strtotime('12/3/1973 8:13am');
$date2 = strtotime('1/15/1974 10:15pm');
$date3 = strtotime('2/14/2005 1:32pm');
// Calculate the differences, they should be 43 & 11353
echo "<p>There are ", count_days($date1, $date2), " days.</p>";
echo "<p>There are ", count_days($date2, $date3), " days.</p>";
?>
Calculate date or time difference.
/**
* Function to calculate date or time difference. Returns an array or
* false on error.
*
* @author MFJ <faisal.hexa@gmail.com>
* @copyright Copyright © 2007, MFJ
* @link http://www.gidnetwork.com/b-16.html Get the date / time difference with PHP
* @param string $start
* @param string $end
* @return array
*/
function get_time_difference( $start, $end )
{
$uts['start'] = strtotime( $start );
$uts['end'] = strtotime( $end );
if( $uts['start']!==-1 && $uts['end']!==-1 )
{
if( $uts['end'] >= $uts['start'] )
{
$diff = $uts['end'] - $uts['start'];
if( $days=intval((floor($diff/86400))) )
$diff = $diff % 86400;
if( $hours=intval((floor($diff/3600))) )
$diff = $diff % 3600;
if( $minutes=intval((floor($diff/60))) )
$diff = $diff % 60;
$diff = intval( $diff );
return( array('days'=>$days, 'hours'=>$hours, 'minutes'=>$minutes, 'seconds'=>$diff) );
}
else
{
trigger_error( "Ending date/time is earlier than the start date/time", E_USER_WARNING );
}
}
else
{
trigger_error( "Invalid date/time data detected", E_USER_WARNING );
}
return( false );
}
?>
Email address Validation Script
<?php
function check_email($mail_address) {
$pattern = "/^[\w-]+(\.[\w-]+)*@";
$pattern .= "([0-9a-z][0-9a-z-]*[0-9a-z]\.)+([a-z]{2,4})$/i";
if (preg_match($pattern, $mail_address)) {
$parts = explode("@", $mail_address);
if (checkdnsrr($parts[1], "MX")){
echo "The e-mail address is valid.";
// return true;
} else {
echo "The e-mail host is not valid.";
// return false;
}
} else {
echo "The e-mail address contains invalid charcters.";
// return false;
}
}
check_email("admin@karachicorner.com");
?>
Empty Cashe - Remove Temp Cache
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
?>
Rating, Ranking Code
<HTML>
<HEAD>
<title>Reader Rated Most Useful Entries</title>
</HEAD>
<BODY>
<table border="0" width="100%">
<tr>
<td width="6%" bgcolor="#00FFFF"><p align="center"><small><font face="Verdana">Rank</font></small></td>
<td width="7%" bgcolor="#00FFFF"><p align="center"><small><font face="Verdana">Rating</font></small></td>
<td width="11%" bgcolor="#00FFFF"><p align="center"><small><font face="Verdana">Diary Date</font></small></td>
<td width="76%" bgcolor="#00FFFF"><p align="left"><small><font face="Verdana">Description
of Diary Page</font></small>
</td>
<script language="php">
$db = "DATABASE NAME";
$admin = "MYSQL USER NAME";
$adpass = "MYSQL PASSWORD";
$mysql_link = mysql_connect("localhost", $admin, $adpass);
mysql_select_db($db, $mysql_link);
$query = "SELECT * FROM avg_tally ORDER BY average DESC";
$result = mysql_query($query, $mysql_link);
if(mysql_num_rows($result)) {
$rank = 1;
while($row = mysql_fetch_row($result))
{
print("</tr><tr>");
if($color == "#D8DBFE") {
$color = "#A6ACFD";
} else {
$color = "#D8DBFE";
}
print("<td width=\"6%\" bgcolor=\"$color\"><center><small>");
print("<font face=\"Verdana\">$rank</font></small></center></td>");
print("<td width=\"7%\" bgcolor=\"$color\"><center><small>");
print("<font face=\"Verdana\"><strong>$row[1]</strong></font></small></center></td>");
print("<td width=\"11%\" bgcolor=\"$color\"><center><small>");
$url = $row[2] . ".php3";
if(!file_exists($url)) { $url = $row[2] . ".html"; }
print("<font face=\"Verdana\"><a href=\"$url\">$row[2]</a></font></small></center></td>");
print("<td width=\"76%\" bgcolor=\"$color\"><left><small>");
print("<font face=\"Verdana\">$row[3]</font></small></left></td>");
$rank++;
}
}
</script>
</table>
</BODY>
</HTML>
Hide Meta Tags
<BODY>
<?
$all_meta = get_meta_tags("meta_tags.php");
print($all_meta["description"]);
print("<br>");
print($all_meta["keywords"]);
?>
</BODY>
</HTML>
Random URL
<?
$random_url = array("http://www.apniphp.blogspot.com/",
"http://www.worldit-news.blogspot.com/",
"http://www.funzclub.blogspot.com/",
"http://www.karachicorner.blogspot.com/",
"http://www.islamic-information.blogspot.com/",
"http://www.smspk.zxq.com/",
"http://www.jokes.zxq.com/");
$url_title = array("Free PHP Scrips",
"World Information Technology News",
"Fun 4 Every 1",
"Get Inforamtion about Karachi, Pakistan",
"About ISLAM",
"SMS Collection",
"Jokes Collection");
$url_desc = array("- A complete solution of PHP Scripts",
"- Get the latest invention in Information Technology",
"- Funny Pictures, Cartoons and many more funny links",
"- About Karachi",
"- Islamic Infomation",
"- Send Free SMS to your Friends",
"- Submit your Jokes, Send jokes to your Friends");
srand(time());
$sizeof = count($random_url);
$random = (rand()%$sizeof);
print("<center><a href=\"$random_url[$random]\">$url_title[$random]</a> $url_desc[$random]</center>");
?>