Posts Mentioning RSS Toggle Comment Threads | Keyboard Shortcuts

  • chetanweb 9:28 am on January 25, 2010 Permalink | Reply  

    PHP Class : IP Details 

    Class File :

    <?php
    /**
    *    Class IP Details
    *    PHP class for looking into details of a IP address
    *
    *    @author Chetan <xtrmcoder@gmail.com>
    *    @version 05 Sep 2009
    *    @copyright GPL © 2009, Chetan Mendhe
    *    @license http://creativecommons.org/licenses/by-nc-sa/3.0/ Released under a Creative Commons License
    */ 

    class ipdetails
    {
        var 
    $ip;
        protected 
    $api="http://66.84.41.158/ip/?ip=";
        var 
    $details;
        var 
    $xml;
        var 
    $curl;
        
    /**
        *    IP Details Construct
        *    @access public
        *    @param String $ip IP Address Of which the details are to be located.
        *    @return void
        */ 
        
    public function ipdetails($ipaddress)
        {
            
    $this->ip=$ipaddress;
            
    $this->curl=curl_init();
            
    curl_setopt($this->curlCURLOPT_URL$this->api.$this->ip);
            
    curl_setopt($this->curlCURLOPT_CONNECTTIMEOUT2);
            
    curl_setopt($this->curlCURLOPT_RETURNTRANSFER1);
            return 
    true;
        }
           
    /** 
        * Scan for the details of the ip address
        * @access public
        * @return void
        */ 
        
    public function scan()
        {
            
    $this->xml curl_exec($this->curl);
            
    preg_match_all('/<([a-zA-Z0-9].*)>(.*)<\/([a-zA-Z0-9].*?)>\n/',$this->xml,$detail);
            
    $this->details=null;
            
    $this->details=array();
            for(
    $i=0;$i<=count($detail[1])-1;$i++)
            {
                
    $this->details[trim($detail[1][$i])]=$detail[2][$i];
            }
            return 
    true;
        }
        
        
        
    /** 
        * To parse the values of the xml
        * @access private
        * @param String $field The field name of the xml 
        * @return void
        */
        
    private function parsexml($field)
        {
            
    preg_match('/<'.$field.'>(.*?)<\/'.$field.'>/',$this->xml,$output);
            return 
    $output[1];
        }
        
        
        
    /** 
        * Export All the Details as an array
        * @access public
        * @return void
        */
        
    public function get_details_by_array()
        {
            return 
    $this->details;
        }
        
        
        
    /** 
        * Export All the Details as xml
        * @access public
        * @return void
        */
        
    public function exportxml()
        {
            return 
    $this->xml;
        }
        
        
    /** 
        * Return the Country Code of the given ip address
        * @access public
        * @return void
        */
        
    public function get_countrycode()
        {
            return 
    $this->details[CountryCode];
        }
        
        
    /** 
        * Return the Code3 of the given ip address
        * @access public
        * @return void
        */
        
    public function get_code3()
        {
            return 
    $this->details[Code3];
        }
        
        
    /** 
        * Return the Country of the given ip address
        * @access public
        * @return void
        */
        
    public function get_country()
        {
            return 
    $this->details[Country];
        }
        
        
    /** 
        * Return the Region of the given ip address
        * @access public
        * @return void
        */
        
    public function get_region()
        {
            return 
    $this->details[Region];
        }
        
        
    /** 
        * Return the City of the given ip address
        * @access public
        * @return void
        */
        
    public function get_city()
        {
            return 
    $this->details[City];
        }
        
        
    /** 
        * Return the PostalCode of the given ip address
        * @access public
        * @return void
        */
        
    public function get_postalcode()
        {
            return 
    $this->details[PostalCode];
        }
        
        
    /** 
        * Return the Latitude of the given ip address
        * @access public
        * @return void
        */
        
    public function get_latitude()
        {
            return 
    $this->details[Latitude];
        }
        
        
    /** 
        * Return the Longitude of the given ip address
        * @access public
        * @return void
        */
        
    public function get_longitude()
        {
            return 
    $this->details[Longitude];
        }
        
        
    /** 
        * Return the DMAcode of the given ip address
        * @access public
        * @return void
        */
        
    public function get_dmacode()
        {
            return 
    $this->details[DMAcode];
        }
            
        
    /** 
        * Return the Areacode of the given ip address
        * @access public
        * @return void
        */
        
    public function get_areacode()
        {
            return 
    $this->details[Areacode];
        }
        
        
    /** 
        * To set new ip address
        * @access public
        * @return void
        */
        
    public function setip($ipaddress)
        {
            
    $this->ip=$ipaddress;
            return 
    true;
        }
        
        
    /** 
        * To close the class
        * @access public
        * @return void
        */
        
    public function close()
        {
            
    curl_close($this->curl);
            return 
    true;
        }
        
        
        
            
        
        
    }


    And Example to use this Class file :

    <?php
    include("class.ipdetails.php");
    $ip=$_SERVER['REMOTE_ADDR'];
    if(
    $ip="127.0.0.1"){$ip="66.84.41.158";}
    $myip=new ipdetails($ip);
    $myip->scan();

    $CountryCode=$myip->get_countrycode();
    $Code3=$myip->get_code3();
    $Country=$myip->get_country();
    $Region=$myip->get_region();
    $City=$myip->get_city();
    $PostalCode=$myip->get_postalcode();
    $Latitude=$myip->get_latitude();   
    $Longitude=$myip->get_longitude();   
    $DMAcode=$myip->get_dmacode();     
    $Areacode=$myip->get_areacode();  

    $myip->close();

    ?>


    <html>
    <head><title>IP Details/Location Example</title></head>
    <body>
    <center>
    <br /><br />
    <h3><?php echo $ip; ?> Details : </h3><br><br>
    <table>
    <tr><td><b>CountryCode</b></td><td>:</td><td><?php echo $CountryCode ; ?></td></tr>
    <tr><td><b>Code3</b></td><td>:</td><td><?php echo $Code3; ?></td></tr>
    <tr><td><b>Country</b></td><td>:</td><td><?php echo $Country; ?></td></tr>
    <tr><td><b>Region</b></td><td>:</td><td><?php echo $Region; ?></td></tr>
    <tr><td><b>City</b></td><td>:</td><td><?php echo $City; ?></td></tr>
    <tr><td><b>PostalCode</b></td><td>:</td><td><?php echo $PostalCode; ?></td></tr>
    <tr><td><b>Latitude</b></td><td>:</td><td><?php echo $Latitude; ?></td></tr>
    <tr><td><b>Longitude</b></td><td>:</td><td><?php echo $Longitude; ?></td></tr>
    <tr><td><b>DMAcode</b></td><td>:</td><td><?php echo $DMAcode; ?></td></tr>
    <tr><td><b>Areacode</b></td><td>:</td><td><?php echo $Areacode; ?></td></tr>

    </table>
    </center>
    </body>
    </html>

     
    • Shashank Amin 2:14 pm on January 25, 2010 Permalink | Reply

      Great yaar was waiting for your blog to update :) Thanks for the code ;)

    • ABHISHEK 5:57 am on January 26, 2010 Permalink | Reply

      thanx for d code

  • chetanweb 6:04 am on January 11, 2010 Permalink | Reply
    Tags: bot, , qoutes, twitter   

    Twitter Bot : Post Qoutes to twitter automaticly via PHP 

    I made this code for my personal use but now thought of sharing this it over here.On execution this PHP will post a tweet in your profile via twitter api . Tweet will have a beautiful quote or saying.Set this PHP execution over a cron job or scheduled jobs.

    <?php
    echo realpath("twitter.php");
    echo 
    "<br>";

    $type[0]="love";
    $type[1]="friendship";
    $type[2]="life";
    $type[3]="funny";
    $type[4]="inspirational";
    $type[5]="money";
    $type=$type[rand(0,5)];
    $curl curl_init();
    curl_setopt($curlCURLOPT_URL"http://www.quotesdaddy.com/widget/tag/$type");
    curl_setopt($curlCURLOPT_CONNECTTIMEOUT2);
    curl_setopt($curlCURLOPT_RETURNTRANSFER1);
    $q curl_exec($curl);
    curl_close($curl);
    $q=explode("&ldquo;",$q);
    $q=explode("&rdquo;",$q[1]);
    $q=$q[0];
    $username '[username]';
    $password '[password]';
    $status urlencode(stripslashes(urldecode($q)));

    if ($status) {
    $tweetUrl 'http://www.twitter.com/statuses/update.xml';

    $curl curl_init();
    curl_setopt($curlCURLOPT_URL"$tweetUrl");
    curl_setopt($curlCURLOPT_CONNECTTIMEOUT2);
    curl_setopt($curlCURLOPT_RETURNTRANSFER1);
    curl_setopt($curlCURLOPT_POST1);
    curl_setopt($curlCURLOPT_POSTFIELDS"status=$status");
    curl_setopt($curlCURLOPT_USERPWD"$username:$password");

    $result curl_exec($curl);
    $resultArray curl_getinfo($curl);

    if ($resultArray['http_code'] == 200)
    echo 
    'Tweet Posted';
    else
    echo 
    'Could not post Tweet to Twitter right now. Try again later.';

    curl_close($curl);
    }
    ?>


     
    • Shashank Amin 6:28 am on January 11, 2010 Permalink | Reply

      Oh now i came to know how does your status on onkut keeps on changing :P

      • Shashank Amin 6:28 am on January 11, 2010 Permalink | Reply

        orkut* :P

      • Shashank Amin 6:48 am on January 11, 2010 Permalink | Reply

        And could you share the script for orkut also please :(

        • chetanweb 12:00 pm on January 11, 2010 Permalink | Reply

          Thats something uniq about my profile !! :P I dont want to make it common :) Sorry

    • ace 9:52 am on January 11, 2010 Permalink | Reply

      nice thanks for the source…

    • Chetan 1:44 pm on January 21, 2010 Permalink | Reply

      I made one for facebook.com also will be posting soon ;)

      • Shashank Amin 8:07 am on January 24, 2010 Permalink | Reply

        will be waiting :)

    • Jack 10:06 am on February 14, 2010 Permalink | Reply

      looks like this script doesn’t work anymore.
      Am i missing something ?

Get Adobe Flash playerPlugin by wpburn.com wordpress themes
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel