Location: PHPKode > projects > Spam free PHP GuestBook > guestbook/gb/include/functions.php
<?php
/*
Copyright (c) 2008 http://ramui.com. All right reserved.
This product is protected by copyright and distributed under licenses restricting copying, distribution. Permission is granted to the public to download and use this script provided that this Notice and any statement of authorship are reproduced in every page on all copies of the script.
*/
function fw_strip_slashes($str)
{
        if (get_magic_quotes_gpc()){return stripslashes($str);}
        return $str;
}
function fw_total_page($c, $p)
{
        if ($c<1){ return 1;}
        $d=$c;
        for ($i=1; $i<=$c; $i++){
            $d=$d-$p;
            if ($d<=0){ return $i;}
        }
}
function fw_random()
{
         $str='abcdefghijklmnopqrstuvwxyz_0123456789';
         $random='';
         $length=rand(8,16);
         for($i=0; $i<$length; $i++){$random.=$str{rand(0,36)};}
         return $random;
}
function fw_get_docroot()
{
		$docroot=str_replace($_SERVER['DOCUMENT_ROOT'],'',str_replace('\\','/',__FILE__));
        return(str_replace('gb/include/functions.php','',$docroot));
}
function fw_validate_user($name,$email)
{
         $reference='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
         $length=strlen($name);
         if(($length>10)||($length<5)){return false;}
         for($i=0; $i<$length; $i++){if(strpos($reference,$name{$i})===false){return false;}}
         return(fw_validate_email($email));
}
function fw_validate_email($email)
{
         $reference='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.@';
         $length=strlen($email);
         if(($length<7)||($length>110)){return false;}
         for($i=0; $i<$length; $i++){if(strpos($reference,$email{$i})===false){return false;}}
         if(strpos($reference,substr($email,0,1))>61){return false;}
         if(strpos($reference,substr($email,-1))>61){return false;}
         return true;
}
function fw_validate_password($pass)
{
         $reference='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_?/:(){}[]0123456789';
         $length=strlen($pass);
         if(($length>12)||($length<6)){return false;}
         for($i=0; $i<$length; $i++){if(strpos($reference,$pass{$i})===false){return false;}}
         return true;
}
function fw_remove_smarttag($s)
{
         $s=str_replace('%u201C','"',str_replace('%u201D','"',$s));
         $s=str_replace("%u2018","'",str_replace("%u2019","'",$s));
         return str_replace("%u2013","-",$s);
}
function fw_php2javascript($text)
{
		return str_replace("\r",'\r',str_replace("\n",'\r',addslashes($text)));
}
?>
Return current item: Spam free PHP GuestBook