Kategori arşivi: Php

Unlimited level of menu through PHP and mysql

 

SELECT id, parent_id, title, link, position FROM menu_item ORDER BY parent_id, position;

 

$html = '';
$parent = 0;
$parent_stack = array();

// $items contains the results of the SQL query
$children = array();
foreach ( $items as $item )
    $children[$item['parent_id']][] = $item;

while ( ( $option = each( $children[$parent] ) ) || ( $parent > 0 ) )
{
    if ( !empty( $option ) )
    {
        // 1) The item contains children:
        // store current parent in the stack, and update current parent
        if ( !empty( $children[$option['value']['id']] ) )
        {
            $html .= '<li>' . $option['value']['title'] . '</li>';
            $html .= '<ul>'; 
            array_push( $parent_stack, $parent );
            $parent = $option['value']['id'];
        }
        // 2) The item does not contain children
        else
            $html .= '<li>' . $option['value']['title'] . '</li>';
    }
    // 3) Current parent has no more children:
    // jump back to the previous menu level
    else
    {
        $html .= '</ul>';
        $parent = array_pop( $parent_stack );
    }
}

// At this point, the HTML is already built
echo $html;

php ile ip adresinden şehir bilgisi bulmak

 <?php 
$ip=$_GET['ip'];
$curl_oturumu =curl_init("http://www.ip-adress.com/");
curl_setopt($curl_oturumu, CURLOPT_HEADER, 0);
curl_setopt($curl_oturumu, CURLOPT_POSTFIELDS, "QRY=$ip");
curl_setopt($curl_oturumu, CURLOPT_RETURNTRANSFER  ,1);
curl_setopt($curl_oturumu, CURLOPT_FOLLOWLOCATION  ,1);
$output= curl_exec($curl_oturumu);
curl_close($curl_oturumu);  
$desc = '#IP Location:(.*?)</b>#si';
preg_match_all($desc,$output,$ddesc);
$sonuc = $ddesc[0][0];
print_r(strip_tags($sonuc)); 
?>

Php Gd Create Thumbnail (crop)

<?php
    function createThumbnail($fileSrc,$thumbDest,$thumb_width,$thumb_height){
        $ext=strtolower(substr($fileSrc,strrpos($fileSrc,".")));
        if($ext==".png"){
            @$base_img = ImageCreateFromPNG($fileSrc);
        }else if(($ext==".jpeg") || ($ext == ".jpg")){
            @$base_img = ImageCreateFromJPEG($fileSrc);
        }else if(($ext == ".gif")){
            @$base_img = imagecreatefromgif($fileSrc);
        }
        if(!$base_img) return false;

        $img_width = imagesx($base_img);
        $img_height = imagesy($base_img);

        if($thumb_width <= $thumb_height){
            $size_percent = intval($thumb_height / ($img_height / 100));
            $new_width = intval($size_percent * ($img_width/100));
            $new_height = $thumb_height;
            $difference_width = intval(($new_width - $thumb_width)/2);
            $difference_height = 0;
        }else{
            $size_percent = intval($thumb_width / ($img_width / 100));
            $new_height = intval($size_percent * ($img_height/100));
            $new_width = $thumb_width;
            $difference_width = 0;
            $difference_height = intval(($new_height - $thumb_height)/2);
        }
        $thumb_img = ImageCreateTrueColor($new_width, $new_height);
        ImageCopyResampled($thumb_img,$base_img,0,0,0,0,$new_width,$new_height,$img_width,$img_height);

        $thumb_images = ImageCreateTrueColor($thumb_width, $thumb_height);
        ImageCopyMerge($thumb_images,$thumb_img,0,0,$difference_width,$difference_height,$thumb_width,$thumb_height,100);

        if($ext == ".png"){
            ImagePNG($thumb_images, $thumbDest);
        }else if(($ext == ".jpeg") || ($ext == ".jpg")){
            ImageJPEG($thumb_images, $thumbDest,82);
        }else if($ext == ".gif"){
            ImageGIF($thumb_images, $thumbDest);
        }

        @ImageDestroy($base_img);
        @ImageDestroy($thumb_images);
        @ImageDestroy($thumb_img);

        return true;
    }
?>

OpenX flash player version detect bug

Find the following function in www/admin/lib-swf.inc.php (relative to your OpenX base install directory):

<?php 
function phpAds_SWFVersion($buffer) 
{ 
    if (substr($buffer, 0, 3) == swf_tag_identify || 
        substr($buffer, 0, 3) == swf_tag_compressed) 
        return ord(substr($buffer, 3, 1)); 
    else 
        return false; 
} 
?>

And change that to:

<?php 
function phpAds_SWFVersion($buffer) 
{ 
    if (substr($buffer, 0, 3) == swf_tag_identify || 
        substr($buffer, 0, 3) == swf_tag_compressed) 
    { 
        $rv = ord(substr($buffer, 3, 1)); 
        if ($rv > 10 && $rv < 13) $rv = 10; 
        elseif ($rv >= 13) $rv = 11; 
        return $rv; 
    } else 
        return false; 
} 
?>

PHP ve SOAP ile TC Kimlik Numarası Doğrulama

<?php
header('Content-type: text/html; charset=utf-8');
$client = new SoapClient("https://tckimlik.nvi.gov.tr/Service/KPSPublic.asmx?WSDL");
try{
    $result = $client->TCKimlikNoDogrula(array( 'TCKimlikNo' => '11111111111','Ad' => 'MEHMET','Soyad' => 'MUTLU','DogumYili' => '1989'));
    if($result->TCKimlikNoDogrulaResult){
        echo 'TC Kimlik Numarası Geçerli';
    }else{
        echo 'TC Kimlik Numarası Hatalı';
    }
}catch (Exception $ex){
    echo $ex->faultstring;
}
?>