martedì 8 gennaio 2013

Convert URL in TynyUrl

function tiny_convert($url) {
    return file_get_contents("http://tinyurl.com/api-create.php?url=" . $url);
}
 
 
//example
 
tiny_convert('tuo_url');
 

domenica 6 gennaio 2013

Zodiac sign §Checker

 
Want to see the zodiac sign of something? using this function to display the zodiac of the object.
 
<?php function zodiac($DOB){
    
$DOB date("m-d"strtotime($DOB));
    list(
$month,$day) = explode("-",$DOB);
    if((
$month == || $month == 4) && ($day 22 || $day 21)){
        
$zodiac "Aries";
    }
    elseif((
$month == || $month == 5) && ($day 22 || $day 22)){
        
$zodiac "Taurus";
    }
    elseif((
$month == || $month == 6) && ($day 23 || $day 22)){
        
$zodiac "Gemini";
    }
    elseif((
$month == || $month == 7) && ($day 23 || $day 23)){
        
$zodiac "Cancer";
    }
    elseif((
$month == || $month == 8) && ($day 24 || $day 22)){
        
$zodiac "Leo";
    }
    elseif((
$month == || $month == 9) && ($day 23 || $day 24)){
        
$zodiac "Virgo";
    }
    elseif((
$month == || $month == 10) && ($day 25 || $day 24)){
        
$zodiac "Libra";
    }
    elseif((
$month == 10 || $month == 11) && ($day 25 || $day 23)){
        
$zodiac "Scorpio";
    }
    elseif((
$month == 11 || $month == 12) && ($day 24 || $day 23)){
        
$zodiac "Sagittarius";
    }
    elseif((
$month == 12 || $month == 1) && ($day 24 || $day 21)){
        
$zodiac "Cpricorn";
    }
    elseif((
$month == || $month == 2) && ($day 22 || $day 20)){
        
$zodiac "Aquarius";
    }
    elseif((
$month == || $month == 3) && ($day 21 || $day 21)){
        
$zodiac "Pisces";
    }

    return 
$zodiac;
}
echo 
zodiac('1986-07-22'); //Valid strtotime date ?>

IP blacklist check script

Enter any suspicious IP address that you wanted to check into the form field and press the "LOOKUP" button
 
 
 
<html>
    
<head>
        
<title>DNSBL Lookup Tool - IP Blacklist Check Script</title>
    
</head>
    
<body>
        
<form action="" method="get">
            
<input type="text" value="" name="ip" />
            
<input type="submit" value="LOOKUP" />
        
</form>
        
<?php
        
/***************************************************************************************
        This is a simple PHP script to lookup for blacklisted IP against multiple DNSBLs at once.

        You are free to use the script, modify it, and/or redistribute the files as you wish.

        Homepage: http://dnsbllookup.com
        ****************************************************************************************/
        
function dnsbllookup($ip){
            
$dnsbl_lookup=array("dnsbl-1.uceprotect.net","dnsbl-2.uceprotect.net","dnsbl-3.uceprotect.net","dnsbl.dronebl.org","dnsbl.sorbs.net","zen.spamhaus.org"); // Add your preferred list of DNSBL's
            
if($ip){
                
$reverse_ip implode("."array_reverse(explode("."$ip)));
                foreach(
$dnsbl_lookup as $host){
                    if(
checkdnsrr($reverse_ip.".".$host.".""A")){
                        
$listed .= $reverse_ip.'.'.$host.' <font color="red">Listed</font><br />';
                    }
                }
            }
            if(
$listed){
                return 
$listed;
            }else{
                return 
'"A" record was not found';
            }
        }
        
$ip=$_GET['ip'];
        if(isset(
$_GET['ip']) && $_GET['ip']!=null){
            if(
filter_var($ip,FILTER_VALIDATE_IP)){
                echo 
dnsbllookup($ip);
            }else{
                echo 
"Please enter a valid IP";
            }
        }
        
?>

    
</body>
</html>

sabato 5 gennaio 2013

PHP Tag Cloud Script

Ever see those sections on websites where some links are bigger than others? This is that! Simply passs an associative array of strings, and "weight", then echo the result.
<?php function gettaCloud$data = array(), $minFontSize 12$maxFontSize 30 )  
{  
    
$minimumCount min($data);  
    
$maximumCount max($data);  
    
$spread       $maximumCount $minimumCount;  
    
$cloudHTML    '';  
    
$cloudTags    = array();  
  
    
$spread == && $spread 1;  
  
    foreach( 
$data as $tag => $count )  
    {  
        
$size $minFontSize + ( $count $minimumCount )  
            * ( 
$maxFontSize $minFontSize ) / $spread;  
        
$cloudTags[] = '<a style="font-size: ' floor$size ) . 'px'  
        
'" class="tag_cloud" href="#" title="\'' $tag  .  
        
'\' returned a count of ' $count '">'  
        
htmlspecialcharsstripslashes$tag ) ) . '</a>';  
    }  
  
    return 
join"\n"$cloudTags ) . "\n";  
}
//Usage Example

$arr 
= Array('Actionscript' => 35'Adobe' => 22'Array' => 44'Background' => 43,  
    
'Blur' => 18'Canvas' => 33'Class' => 15'Color Palette' => 11'Crop' => 42,  
    
'Delimiter' => 13'Depth' => 34'Design' => 8'Encode' => 12'Encryption' => 30,  
    
'Extract' => 28'Filters' => 42);  
echo 
gettaCloud($arr1236);
 ?>

Twitter feed reader

Take a user name, and load the user feed to display on a page.
 
 
<?php class Twitter{
    protected 
$twitURL 'http://api.twitter.com/1/';
    protected 
$xml;
    protected 
$tweets  = array(), $twitterArr = array();
    protected 
$pversion "1.0.0";
    public function 
pversion(){
        return 
$this->pversion;
    }
    public function 
loadTimeline($user$max 20){
        
$this->twitURL .= 'statuses/user_timeline.xml?screen_name='.$user.'&count='.$max;
        
$ch        curl_init();
        
curl_setopt($chCURLOPT_URL$this->twitURL);
        
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
        
$this->xml curl_exec($ch);
        return 
$this;
    }
    public function 
getTweets(){
        
$this->twitterArr $this->getTimelineArray();
        
$tweets = array();
        foreach(
$this->twitterArr->status as $status){
            
$tweets[$status->created_at->__toString()] = $status->text->__toString();
        }
        return 
$tweets;
    }
    public function 
getTimelineArray(){
        return 
simplexml_load_string($this->xml);
    }
    public function 
formatTweet($tweet){
        
$tweet preg_replace("/(http(.+?))( |$)/","<a href=\"$0\">$1</a>$3"$tweet);
        
$tweet preg_replace("/#(.+?)(\h|\W|$)/""<a href=\"https://twitter.com/i/#!/search/?q=%23$1&src=hash\">#$1</a>$2"$tweet);
        
$tweet preg_replace("/@(.+?)(\h|\W|$)/""<a href=\"http://twitter.com/#!/$1\">@$1</a>$2"$tweet);
        return 
$tweet;
    }
}
 
//Usage Example

$twitter 
= new Twitter(); $feed $twitter->loadTimeline("insertusername")->getTweets();
foreach(
$feed as $time => $message){
    echo 
"<div class='tweet'>".$twitter->formatTweet($message)."<br />At: ".$time."</div>";
}
 ?>

Calculate distance between points

This function will calculate the distance between point A (latitude, longitude) and point B (latitude, longitude) returning a distance in miles.


<?php function lat_long_dist($lat1$long1$lat2$long2){
    
$pi pi();
    
$x  sin($lat1 $pi/180) * 
          
sin($lat2 $pi/180) + 
          
cos($lat1 $pi/180) * 
          
cos($lat2 $pi/180) * 
          
cos(($long2 $pi/180) - ($long1 $pi/180));
    
$x  atan((sqrt(pow($x2))) / $x);
    return (
1.852 60.0 * (($x/$pi) * 180)) / 1.609344;
}


echo 
lat_long_dist(56.3434249.32452357.4954447.421524);

giovedì 3 gennaio 2013

Age calculator

This function will take a birthday and calculate an age.
 
<?php function birthday($birthday){
    
$age strtotime($birthday);
    if(
$age === false){
        return 
false;
    }
    list(
$y1,$m1,$d1) = explode("-",date("Y-m-d",$age));
    
$now strtotime("now");
    list(
$y2,$m2,$d2) = explode("-",date("Y-m-d",$now));
    
$age $y2 $y1;
    if((int)(
$m2.$d2) < (int)($m1.$d1))
        
$age -= 1;
    return 
$age;
}

echo 
birthday('1986-07-22'); ?>

ASCII Captcha

Why use an image to make a CAPTCHA? Use ASCII to do it (takes a few extra seconds to load but twice as secure)!



<html>
<head>
<title>Ascii</title>
<style>
#CAPTCHA
{
    font-size
:1px;
    line-height
:1px;
}
</style>
</head>
<body>
    
<?php
    
// Get the fonts for the CAPTCHA
    
$fonts glob'examples/CAPTCHA/fonts/*');
    
// Build a String
    
$string md5(rand(0,5000));
    
// Get the first 4 letters and place it in an array
    
$string substr($string,0,4);
    
$letters str_split($string);
    
// Set the CAPTCHA Height
    
$ih 60;
    
// Set the CAPTCHA Width
    
$iw 130;
    
// Set the Font size
    
$fs 25;
    
// Create an image
    
$image imagecreatetruecolor($iw,$ih);
    
// Set a default background color
    
$white imagecolorallocate($image255255255);
    
// Add the background color to the image
    
imagefilledrectangle($image00$iw$ih$white);
    
// Set minimum letter y position
    
$y_min = ($ih 2) + ($fs 3) - 10;
    
// Set maximum letter y position
    
$y_max = ($ih 2) + ($fs 3) + 10;
    
// Set the letter starting point
    
$x $fs;
    
// Set i to zero
    
$i 0;
    
// Loop through each letter
    
foreach($letters as $letter){
        
// Set the angle of the letter random from -45 and 45
        
$angle rand(-4545);
        
// Set a random y position of the letter using using the above min and max
        
$y rand($y_min$y_max);
        
// check to see if this is first letter, yes then skip next line otherwise,
        // add font size to x to move letter to the right
        
if($i != 0)
            
$x += $fs;
        
// Set the color of the letter
        
$font_color imagecolorallocate($imagerand(50,200), rand(50,200), rand(50,200));
        
// Choose a random font from our list of fonts
        
$rand array_rand($fonts);
        
// Add letter to the image
        
imagettftext($image$fs$angle$x$y$font_color$fonts[$rand], $letter);
        
// Incrament $i
        
$i++;
    }
    
// Finally build the image!
    
$black imagecolorallocate($image000);
    
// Build the ASCII image
    
echo '<div id="CAPTCHA">';
    for(
$h=0;$h<$ih;$h++){
        for(
$w=0;$w<=$iw;$w++){
            
$rgb imagecolorat($image$w$h);
            
$r = ($rgb >> 16) & 0xFF;
            
$g = ($rgb >> 8) & 0xFF;
            
$b $rgb 0xFF;
            if(
$w == $iw){
                echo 
'<br />';
            }else{
                echo 
'<span style="color:rgb('.$r.','.$g.','.$b.');">#</span>';
            }
        }
    }
    echo 
'</div>';
    
//End ASCII Image Build
    
$_SESSION['CAPTCHA'] = $string;
    
?>

<p>
    Image String:
<?php echo $_SESSION['CAPTCHA']; ?>
</p>
</body>
</html>

AJAX Chat

AJAX Chat is a free and fully customizable open source web chat implemented in JavaScript, PHP and MySQL which integrates nicely with common forum systems like phpBB, MyBB, PunBB, SMF and vBulletin. A Flash and Ruby based socket connection can be used to boost performance.

 

Download

https://github.com/Frug/AJAX-Chat/zipball/master


Please do not email the devs with support questions.
For general support questions use our google group.
Check out the wiki at https://github.com/Frug/AJAX-Chat/wiki.

New Blog Channel It's Open!

Hello friends, now you can find all the information held on the new blog.
http://php-source-code.blogspot.it/

Friends