Wednesday, November 23, 2011

php Util Classes

Php connection util Classes Code


code: save file UtilClass.php
<?php
class UtilClass {
    public $utilMySqlServerIP;
    public $utilDB ;
    public $utilUser;
    public $utilPass;
    public $utilLink,$utilIsMYSQLLinked,$utilIsDBConnected;
    public static $utilTitle,$utilDescription,$utilKeywords,$utilAuthor;
    public $utilAns;
   
    public function __construct() {
        $this->utilMySqlServerIP = "localhost";
        $this->utilUser = "root";//"root";
        $this->utilPass = "";//"";
        $this->utilDB = "photo-gallery";
        $this->utilAns=false;
    }
    /////////////////// Start SEO Functions ///////////////////////////////////////////////
    public static function getTitle() {
        self::$utilTitle="Photo Gallety";
        return (self::$utilTitle);
    }
    public static function getDescription(){
        self::$utilDescription="Description";
        return (self::$utilDescription);   
    }
    public static function getKeywords(){
        self::$utilKeywords="Keywords";
        return (self::$utilKeywords);   
    }
    public static function getAuthor(){
        self::$utilAuthor="Author";
        return (self::$utilAuthor);   
    }
    public function getCreatedByName() {
        return "CreatedByName";   
    }
    public function getCreatedByWebAddress() {
        return "CreatedByWebAddress";   
    }
    public function getWebName() {
        return "WebName";   
    }
    public function getWebURL() {
        return "WebURL";   
    }
    /////////////////// End SEO Functions ///////////////////////////////////////////////
   
    /////////////////// Start Host Functions ///////////////////////////////////////////////
    public function getHost() {
        return $this->utilMySqlServerIP;   
    }
    public function getDb() {
        return $this->utilDB;   
    }
    public function getUser() {
        return $this->utilUser;   
    }
    public function getPass() {
        return $this->utilPass;   
    }
    ///////////// Start Date and Time Functins////////////////
    public function todayDDMMMYY($dt,$format='d-M-Y') {
        date_default_timezone_set('Asia/Calcutta');
        return date($format,strtotime($dt));
    }
   
    public function todayMMDDYY( $format = 'm-d-Y h:i:s A' ) {
        date_default_timezone_set('Asia/Calcutta');
        return date($format);
    }
    public function todayYYYYMMDD( $format = 'Y-m-d h:i:s A' ) {
        date_default_timezone_set('Asia/Calcutta');
        return date($format);
    }
    public function toDayDate( $format = 'm/d/Y' ) {
        date_default_timezone_set('Asia/Calcutta');
        return date($format);
    }
    public function toDayYear( $format = 'Y' ) {
        return date($format);
    }
////////////////// Start quoteToDbl Function //////////////////
    public function quoteToDbl(&$input) {
        $input=str_replace("'","''",$input);
        $input=trim($input);
    }
    public function getExtension($str) {
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
     }
   
////////////////// End quoteToDbl Function //////////////////
   
////////////////// Start openCon Function //////////////////
    public function openCon() {
        $utilAns=false;
        try {
            $this->utilLink = mysql_connect($this->utilMySqlServerIP, $this->utilUser, $this->utilPass);
            if (!is_resource($this->utilLink) || !$this->utilLink) {
                $utilAns=false;
                $utilIsMYSQLLinked=false;
            }
            else {
                $utilIsMYSQLLinked=true;
                if(mysql_select_db($this->utilDB,$this->utilLink)) {
                    $utilIsDBConnected=true;
                    $utilAns=true;   
                } else {
                    $utilIsDBConnected=false;
                    $utilAns=false;
                }
            }
           
        }
        catch(Exception $ee){
            $utilIsDBConnected=false;
            $utilIsMYSQLLinked=false;
            $utilAns=false;
        }
        return $utilAns;
    }
    ////////////////// End openCon Function //////////////////
   
    ////////////////// Start sendEMail Function //////////////////
    public function sendEMail($tto, $fFrom, $sSubject, $bBody) {
        /*if($tto=="") {
            $tto="to@to.com";
        }
        if($fFrom=="") {
            $fFrom="from@from.com";
        }
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        $headers .= 'To: '.$tto . "\r\n";
        $headers .= 'From: '.$fFrom . "\r\n";
        mail($tto, $sSubject, $bBody, $headers);*/
        $html_message = $bBody;
        $mail = new PHPMailer();
        $mail->From = $fFrom;
        $mail->FromName = "Test".' '."Mail"; //name
        $mail->Subject = $sSubject;
        $mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
        $mail->MsgHTML($html_message);
        $mail->AddAddress($tto);
        $mail->Username = 'noreply@firstmedicalservices.com';
        $mail->Password = 'noreply';
        $mailAns = $mail->Send();
        return $mailAns;
    }
    ////////////////// End sendEMail Function //////////////////
   
    ////////////////// Start autoGeneratePass Function //////////////////
    public function autoGeneratePass() {
        $newpass="";
        for($i=1;$i<=2;$i++){
            $newpass=$newpass.chr(rand(65, 90));//A-Z
            $newpass=$newpass.chr(rand(48, 57));//0-9
            //$newpass=$newpass.chr(rand(97, 122));//a-z
        }
        return $newpass;
    }
    ////////////////// End autoGeneratePass Function //////////////////
   
    ////////////////// Start makeMD5 Function //////////////////
    public function makeMD5($st) {
        $md=md5($st);
        return $md;
    }
   
    public function counters($fileName) {
        $count = file_get_contents($fileName);//create txt file and give 0 values in .txt file
        $count = trim($count);
        $count = $count + 1;
        $fl = fopen($fileName,"w+");
        fwrite($fl,$count);
        fclose($fl);
    }

    ////////////////// End makeMD5 Function //////////////////
   
    ////////////////// Start exportToExcelUtil Function //////////////////
    public function exportToExcelUtil($filename,$data) {
        header("Content-type: application/octet-stream");
        header("Content-Disposition: attachment; filename=$filename");
        header("Pragma: no-cache");
        header("Expires: 0");
        echo  $data;
    }
    ////////////////// End exportToExcelUtil Function //////////////////
   
    ////////////////// Start secureSql Function //////////////////
    public function secureSql($val) {
        $val = str_ireplace("script", "blocked", $val);
        $val = mysql_escape_string($val);
        $this->quoteToDbl($val);
        return $val;
    }
    ////////////////// End secureSql Function //////////////////
       
    ////////////////// Start getRandomFileName Function //////////////////   
    public function getRandomFileName() {
        $rndFileName=$this->makeMD5($this->today());
        return $rndFileName;
    }
    ////////////////// End getRandomFileName Function //////////////////   
   

    ////////////////// Start getScript Name/ get Current Page Name Function //////////////////   
    function getScript() {
        $file = $_SERVER["SCRIPT_NAME"];
        $break = explode('/', $file);
        $pfile = $break[count($break) - 1];
        return $pfile;
    }
    ////////////////// End getScript Name/ get Current Page Name Function //////////////////

    ////////////////// Start exeQuery Function //////////////////
    public function exeQuery($qry) {
        echo $qry;
        try    {
            $res = mysql_query($qry, $this->utilLink);
            if(!is_resource($res) || (!$res)) {
                $res=false;
            } else {
                $numRows = mysql_num_rows($res);
                if($numRows<=0) {
                    $res=false;
                }
            }
            return $res;
        }
        catch(Exception $ee){
            return (false);
        }
    }
    ////////////////// End exeQuery Function //////////////////
   
    ////////////////// Start closeCon Function //////////////////
    public function closeCon() {
        mysql_close($this->utilLink);   
    }
    ////////////////// End closeCon Function //////////////////
    #----------------------------Start Utility Function ------------------#
   
    public function __destruct() {
        if($this->utilAns==true) {
        $this->closeCon();}
    }
}
?>
code: save file UtilClass.php
<?php
include_once("UtilClass.php");
class classes1 extends UtilClass {
    var $host;
    var $db ;
    var $user;
    var $pass;
    var $link,$isDBConnect;
    var $isError,$errorValue;
    var $dt;
    var $adminEmail,$adminMobile,$adminEmailPass,$adminEmailPort,$adminEmailHost,$scrollText;
   
    function __construct() {
        parent::__construct();
        $this->host = parent::getHost();
        $this->db = parent::getDb();
        $this->user = parent::getUser();
        $this->pass = parent::getPass();
        try {
            $this->link = mysql_connect($this->host, $this->user, $this->pass);
            if (!is_resource($this->link)) {
                $this->isDBConnect=false;
            }
            else {
                $this->isDBConnect=true;
            }
            mysql_select_db($this->db,$this->link);
            $this->getAdminAllInfo();
        }
        catch(Exception $ee){
            $this->link=false;
        }
    }
   
    public function setCon() {
        $this->host = parent::getHost();
        $this->db = parent::getDb();
        $this->user = parent::getUser();
        $this->pass = parent::getPass();
        try {
            $this->link = mysql_connect($this->host, $this->user, $this->pass);
            if (!is_resource($this->link)) {
                $this->isDBConnect=FALSE;
            }
            else {
                $this->isDBConnect=TRUE;
            }
            mysql_select_db($this->db,$this->link);
        }
        catch(Exception $ee){
            $this->link=FALSE;
        }
    }
    public function getTotalRecord($table) {
        $res=false;
        $sSql="SELECT COUNT(*) AS total FROM $table";
        try {
             $rs=$this->exeQuery($sSql);
             if($rs) {
             $fQury=mysql_fetch_array($rs);
             return $fQury['total'];
             }
             else { return 0; }
             
        } catch(Exception $ee){
            $res=false;       
        }
        return $res;           
    }
   
    public function activeDeactive($ID,$isActive,$tb, $colName) {
        $ans="No";
         $sSql="Update $tb set isActive=$isActive where $colName=$ID";
        try {
             $rs=$this->exeQuery($sSql);
             if($rs) {
                 $ans="Yes";
             }  else { $ans="No"; }
             
        } catch(Exception $ee){
            $ans="No";       
        }
        echo $ans;           
    }
    public function deleteRecord($ID,$tb,$colName) {
        $ans="No";
         $sSql="delete from $tb where $colName=$ID";
        try {
             $rs=$this->exeQuery($sSql);
             if($rs) {
                 $ans="Yes";
                //unlink("../images/$dr/$ID.jpg");
             }  else { $ans="No"; }
             
        } catch(Exception $ee){
            $ans="No";       
        }
        echo $ans;           
    }
       
///////////////////////////////////////////////////////////////////////////////////////////
    public function exeQuery($query) {
        $res=false;
        try    {
            $res = mysql_query($query, $this->link);
        }
        catch(Exception $ee){
            $res=false;
        }
        return $res;
    }

    public function getRow($res) {
        $arr = @mysql_fetch_array($res, MYSQL_BOTH);
        return $arr;
    }
   
    public function close()  {
 }
 public function __destruct() {
  mysql_close($this->link);
    }

}
   
?>

Monday, November 21, 2011

Make php counter

Make php counter
Using PHP and a plain text file this has never been easier. The example below uses a flat-text database so no MySQL database is needed. 
First, lets make a new php page and also a count.txt file with just 0 digit in it. Upload the count.txt file on your web server. Depending on server configuration you may need to change the permission for this file to 777 so it is writeable by the counter script that we are going to use. Now, lets do the actual PHP code.  
<?php
$count = file_get_contents("count.txt");
$count = trim($count);
$count = $count + 1;
$fl = fopen("count.txt","w+");
fwrite($fl,$count);
fclose($fl);
include('count.txt');// Show counter
?>
First line opens the count.txt file and reads the current counter value. Then the trim() function is used to remove any new line characters so we have an integer. On the next line we increment the current counter value by one and then using the fopen, fwrite and fclose commands we write the new value to our count.txt file.

Thursday, November 10, 2011

How can track Ip address in php


Here with the help of APPs you can track the ip.
These details include Geographic location information (includes country, region/state, city, latitude, longitude and telephone area code.), 

<?php
 $ip=$_SERVER["REMOTE_ADDR"];
$handle = fopen("http://api.ipinfodb.com/v3/ip-city/?key=5b32848aa72361c4efdef63111d6e3d9247e076891f5248eec0a5be1208993e6&ip=".$ip, 'r');
$tt=fgets($handle, 4096);
echo '<br>';
list($statusCode, $statusMessage, $ipAddress,$countryCode,$countryName,$regionName,$cityName,$zipCode,$latitude,$longitude,$timeZone) = split(';', $tt);
echo "Ip-Address->".$ipAddress;
echo '<br>';
echo "Country Name->".$countryName;
echo '<br>';
echo "Country Code->".str_ireplace('-', '', $countryCode);
echo '<br>';
echo "City Name->".str_ireplace('-', '', $cityName);
fclose($handle);

Saturday, November 5, 2011

PHP script to delete thousands of jpgs


I seen this query on guru.com  but I can not do the  bit this project. But  I done this task.  
Client Requirement

Hi, my webcam is uploading .jpg files to my shared webhost and I need you to create and install a php script that will delete all .jpg files in the public_html/cams/ folder and subfolders. Because there are so many images the script must find and delete images in small batches so that it doesn't crash my shared server. It must be able to find and delete jpg images in all subfolders of the cams/ directory. ( I add new folders for new cams sometimes and I don't want to have to update the script each time I add a new subfolder with cam images ).

It should only delete .jpg files that have dates in them like:
cams/cable/2011-10-14_14-15-42.jpg

Solution :
I have solve your problem with the help of php script,
My  script delete  public_html/cams/ “ only .jpg file all file’s.
My  script delete  public_html/cams/ folder”  only .jpg file all file’s.
My  script delete  public_html/cams/ folder/sub-folder”  only .jpg file all file’s.
My Script go on (Work) 3 sub folders and increase many subfolder on clients demand.   


Friday, November 4, 2011

jQuery Roundabout

HTML is added into each box, when it moves to the back it doesn't scale correctly. It keeps the same size. Ideally I'd like it to scale to match, but not having much look.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head >
<title>
</title>
<link href="css/commonstyles.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" language="javascript" src="scripts/jquery.min.js"></script>
    <script type="text/javascript" language="javascript" src="scripts/jquery-ui.min.js"></script>
    <script src="scripts/jquery.roundabout.js" type="text/javascript"></script>
    <script src="scripts/default.js" type="text/javascript"></script>
</head>
<body>
    <div>
            <div id="divTestimonialContainer">
            <ul id="TestimonialRoundAbout">
                <li>
                   <div><img src="commonimages/kp.jpg" alt="Kaiser Permanente" height="200" width="300" /></div>
                </li>
                <li>
                    <div><img src="commonimages/countrywide.jpg" alt="Countrywide Home Loans" height="200" width="300"  /></div>
                </li>
                
                <li>
                    <div><img src="commonimages/indianfantasyleague.jpg" alt="Indian Fantasy League" height="200" width="300"  />
                    </div>
                </li>
                <li>
                   <div><img src="commonimages/amgen.jpg" alt="Amgen" height="200" width="300"  /></div>
             
            </ul>
            </div>
    </div>
<script type="text/javascript">
//<![CDATA[
$(function() { Default();});//]]>
</script>
</body>
</html>
click to demo 

How to create xml file with php code

how to create xml file with php code

Here you learn create xml file with the help of php
<?php

$xml = new SimpleXMLElement("<?xml version='1.0' encoding='iso-8859-1'?><content/>");

$track = $xml->addChild('section');
$track->addAttribute('name','settings');

$item=$xml->addChild('item', 'true');
$item->addAttribute('name','textSelectable');

$item=$xml->addChild('item', 'gold');
$item->addAttribute('name','copyright');

$item=$xml->addChild('item', 'Silver');
$item->addAttribute('name','companyName');
$track = $xml->addChild('section');

?>