+ Reply to Thread
Results 1 to 3 of 3

Thread: Small PHP Codes | Snippets

  1. #1
    Major Advisor
    Join Date
    Sep 2006
    Location
    India
    Posts
    204

    Default Small PHP Codes | Snippets

    function to get real ip.

    PHP Code:
    function getRealIpAddr()
    {
        if (!empty(
    $_SERVER['HTTP_CLIENT_IP']))
        {
            
    $ip=$_SERVER['HTTP_CLIENT_IP'];
        }
        elseif (!empty(
    $_SERVER['HTTP_X_FORWARDED_FOR']))
        
    //to check ip is pass from proxy
        
    {
            
    $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
        }
        else
        {
            
    $ip=$_SERVER['REMOTE_ADDR'];
        }
        return 
    $ip;


  2. #2
    Major Advisor
    Join Date
    Sep 2006
    Location
    India
    Posts
    204

    Default Re: Small PHP Codes | Snippets

    image watermark with php


    PHP Code:
    <?php  
     
    $main_img         
    "image.jpg"// main big photo / picture
    $watermark_img    "watermark.gif"// use GIF or PNG, JPEG has no tranparency support
    $padding         3// distance to border in pixels for watermark image
    $opacity        100;    // image opacity for transparent watermark
     
    $watermark     imagecreatefromgif($watermark_img); // create watermark
    $image         imagecreatefromjpeg($main_img); // create main graphic
     
    if(!$image || !$watermark) die("Error: main image or watermark could not be loaded!");
     
     
    $watermark_size     getimagesize($watermark_img);
    $watermark_width     $watermark_size[0];  
    $watermark_height     $watermark_size[1];  
     
    $image_size     getimagesize($main_img);  
    $dest_x         $image_size[0] - $watermark_width $padding;  
    $dest_y         $image_size[1] - $watermark_height $padding;
     
     
    // copy watermark on main image
    imagecopymerge($image$watermark$dest_x$dest_y00$watermark_width$watermark_height$opacity);
     
     
    // print image to screen
    header("content-type: image/jpeg");   
    imagejpeg($image);  
    imagedestroy($image);  
    imagedestroy($watermark);
    ?>

  3. #3
    Major Advisor
    Join Date
    Sep 2006
    Location
    India
    Posts
    204

    Default Re: Small PHP Codes | Snippets

    Unzip file using PHP

    PHP Code:
    <?php
     
    // create object
    $zip = new ZipArchive() ;
     
    // open archive
    if ($zip->open(&#8217;archive.zip’) !== TRUE) {
    die (&#8217;Could not open archive’);
    }
     
    // extract contents to destination directory
    $zip->extractTo(&#8217;/ tmp/extracted/ ‘);
     
    // close archive
    // print success message
    $zip->close();
    echo &
    #8216;Archive extracted to directory’;
     
    ?>

+ Reply to Thread

Similar Threads

  1. Limewire Version History
    By admin in forum Changelog (Version History)
    Replies: 4
    Last Post: 05-03-2009, 08:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts