Showing posts with label PHP Functions. Show all posts
Showing posts with label PHP Functions. Show all posts

Thursday 11 June 2015

How To Track the Real IP Address Behind the Proxy - PHP - REMOTE_ADDR

How To Track the Real IP Address Behind the Proxy - PHP - REMOTE_ADDR

IP Address: It is unique address of the client machine by which we track the user detail requesting for some request. Full Fom of IP Address is Internet Protocol Address. today, Almost all person know about the ITp Address. This is basically used for tracking.

For Example, If you send an email with your computer. Communication is done on the behalf of IP Address.

Get the Unique IP Address of client machine

function get_ip_address(){
 if ( !empty($_SERVER['HTTP_CLIENT_IP']) )  //check ip from share internet
 {
   $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;
}

echo get_ip_address();

Saturday 16 May 2015

date_sunrise - Returns time of sunrise for a given day and location

mixed date_sunrise ( int $timestamp [, int $format = SUNFUNCS_RET_STRING [, float $latitude = ini_get("date.default_latitude") [, float $longitude = ini_get("date.default_longitude") [, float $zenith = ini_get("date.sunrise_zenith


Returns time of sunrise for a given day and location
date_sunrise() returns the sunrise time for a given day (specified as a timestamp) and location.

<?php/* calculate the sunrise time for Lisbon, Portugal
Latitude: 38.4 North
Longitude: 9 West
Zenith ~= 90
offset: +1 GMT
*/

echo date("D M d Y"). ', sunrise time : ' .date_sunrise(time(), SUNFUNCS_RET_STRING38.4, -9901);
?>

SUNFUNCS_RET_STRING returns the result as string 16:46 SUNFUNCS_RET_DOUBLE returns the result as float 16.78243132 SUNFUNCS_RET_TIMESTAMP returns the result as integer (timestamp) 1095034606

Wednesday 29 April 2015

Convert image to Binary Data and vice versa in PHP

 Convert image to Binary Data and vice versa in PHP

How to Convert image to Binary Data
$imageURL ='http://www.aboutcity.net/images/web-technology-experts-notes.jpg';
$contents = base64_encode(file_get_contents($imageURL));
/** Now stored the $contentes in Database or In Server**/


/** Now stored the $contentes in Database or In Server**/


How to display the Binary image data in Browser.
/** get the binary image data and stored in $contents variable **/
$contents='BINARY IMAGE DATA';
 echo "<img src="data:image/jpg;charset=utf8;base64,$contents" />";


How to get the image size (Height and Width) from binary data 
$file ='http://www.aboutcity.net/images/web-technology-experts-notes.jpg';
$contents = file_get_contents($file);
          
$image = imagecreatefromstring($contents);
echo 'Width: '.imagesx($image);
echo "\n";
echo 'Height: '.imagesy($image);





Tuesday 10 March 2015

Difference between in_array and array_key_exists in php with example

Difference between in_array and array_key_exists in php with example

in_array: Checks if a value exists in an array OR not.
bool in_array ( mixed $needle , array $haystack [, bool $strict = FALSE ] );

Parameters
needle: The searched value.
haystack: The array.
strict: If the third parameter strict is set to TRUE then the in_array() function will also check the types of the needle in the haystack.

Return: Returns TRUE if needle is found in the array, FALSE otherwise.

Example:
$array = array("Web", "Technology", "Experts", "Notes");
if (in_array("Technology", $array)) {
    echo "Record Found in value";
}



array_key_exists: Checks if the given key/index exists in the array.
bool array_key_exists ( mixed $key , array $array );
Parameters key: Value to check.
array: An array with keys to check.

Return: Returns TRUE on success or FALSE on failure.

Example:
$searchArray = array('Web' => 1, 'Technology' => 4);
if (array_key_exists('Web', $searchArray)) {
    echo "Record Found in key";
}

Tuesday 16 December 2014

get_class_vars PHP Function

array get_class_vars ( string $class_name )
Get the default properties of the class
Get the default properties of the given class.

<?phpclass myclass {

    var 
$var1// this has no default value...
    
var $var2 "xyz";
    var 
$var3 100;
    private 
$var4// PHP 5

    // constructor
    
function myclass() {
        
// change some properties
        
$this->var1 "foo";
        
$this->var2 "bar";
        return 
true;
    }

}
$my_class = new myclass();$class_vars get_class_vars(get_class($my_class));

foreach (
$class_vars as $name => $value) {
    echo 
"$name : $value\n";
}
?>


OOP PHP #16 : fungsi get_class_vars() dan get_class_method