PHP Scripts

Website Security Against Hackers

This script is very simple.

If you haven't experienced someone hacking your website, then that's good.

If you want to know, however, if someone does sneak in and make subtle changes like injecting javascript to change the title and description, or even to use the CPU power of the host to do mass mailouts, here it is ...

1. Connect to the database
2. Create a table, like "sizes" with one column, default NULL, varchar 250, called "size"
3. Upload the file, run it, and then bookmark it in your browser, to check as often as you like.

<?php

// get the size in bytes of your website
$path = getcwd();
function filesize_r($path){
if(!file_exists($path)) return 0;
if(is_file($path)) return filesize($path);
$ret = 0;
foreach(glob($path."/*") as $fn)
$ret += filesize_r($fn);
return $ret;
}
$size=filesize_r($path);

// connect to your database and add new
$db = mysql_connect("host", "login", "password");
mysql_select_db("table",$db);

$query="SELECT * FROM sizes";
$resultss = mysql_query( $query, $db );
$num_rowss = mysql_num_rows($resultss);
if (empty($num_rowss)) {
$q1 = "INSERT INTO sizes (size) VALUES ('$size')";
mysql_query($q1) or die("$q1 failed because ".mysql_error());
} else {

// or compare, and update website size
$d=mysql_result($resultss,$zz,"size");
if ($d == $size) {
} else {
$q2 = "UPDATE sizes SET size='$size'";
mysql_query($q2) or die("$insert failed because ".mysql_error());

// if the website size has changed, email yourself
mail("your email ",
"Website Filesize Change ",
"\nOld data size:$d\n\nNew data size:$size\n\n",
"From: Your Website <your email >");
}
}
mysql_free_result($resultss);
mysql_close($db);
?>

 

 

Back