My Main Blog

Friday, 31 October 2014

Download image without cURL and with cURL in PHP

Download image without cURL and with cURL in PHP




<?php
// without cURL
$downloadImageUrl="http://fc04.deviantart.net/fs26/f/2008/072/b/1/Frozen_Galaxy_by_Vpr87.jpg";
////// Using without CURL
$img = file_get_contents($downloadImageUrl);
$file1 = dirname(__file__).'/aaa.jpg';
file_put_contents($file1, $img);



////// // with cURL
$fileName=$downloadImageUrl;
$header = array(
            "Accept-Encoding: gzip,deflate",
            "Accept-Charset: utf-8;q=0.7,*;q=0.7",
            "Connection: close"
        );
$useragent = 'Amit Kumar Gaur amitt800@gmail.com  http://amitkgaur.blogspot.com';
$file2 = dirname(__file__).'/bbb.jpg';
$curlObj=curl_init();
curl_setopt($curlObj, CURLOPT_HTTPHEADER, $header);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlObj, CURLOPT_HEADER, false);
curl_setopt($curlObj, CURLOPT_USERAGENT, $useragent);
curl_setopt($curlObj, CURLOPT_CONNECTTIMEOUT, 999);
curl_setopt($curlObj, CURLOPT_TIMEOUT, 9999);
curl_setopt($curlObj, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($curlObj, CURLOPT_URL, $downloadImageUrl);
$response = curl_exec($curlObj);
$return = false;
if(!curl_errno($curlObj)) {
    file_put_contents($file2, $response);
}
?>

Orbital chase paymentech gateway

Orbital Chase Paymentech Gateway Mark for Capture

Chase Orbital is one of the complex Payment Gateway. It's authorization process is very complex.
Here is the code for Orbital Chase Paymentech Gateway Mark for Capture Request in PHP.
You can frequently use it as free.


<?php
$url = "https://orbitalvar2.paymentech.net"; // testing
//$url = "https://orbital1.paymentech.net"; // production
$post_string="
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
    <Request>
        <MarkForCapture>
            <OrbitalConnectionUsername>YOUR-USERNAME-HERE</OrbitalConnectionUsername>
            <OrbitalConnectionPassword>YOUR-PASSWORD-HERE</OrbitalConnectionPassword>
            <OrderID>123456789</OrderID>
            <Amount>8500</Amount>
            <BIN>000002</BIN>
            <MerchantID>YOUR-MERCHANT-ID-HERE</MerchantID>
            <TerminalID>001</TerminalID>
            <TxRefNum>4F320B79F23280DAE62777C80721F838FF13548D</TxRefNum>
        </MarkForCapture>
    </Request>";
    $header= "POST /authorize/ HTTP/1.0\r\n";
    $header.= "MIME-Version: 1.0\r\n";
    $header.= "Content-type: application/PTI\r\n";
    $header.= "Content-length: "  .strlen($post_string) . "\r\n";
    $header.= "Content-transfer-encoding: text\r\n";
    $header.= "Request-number: 1\r\n";
    $header.= "Document-type: Request\r\n";
    $header.= "Interface-Version: Test 1.4\r\n";
    $header.= "Connection: close \r\n\r\n";
    $header.= $post_string;
 
   //// just initialize curl here and post the data to the orbital server.


 
?>

Thursday, 30 October 2014

Latitude Longitude by address in php

How to find Latitude Longitude by address in php.


You can find very easily Latitude and Longitude by given address with combination of Google map api and php.

<?php
    $address = 'Sector 37,Noida,India';
    $geocode = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($address) . '&sensor=true');
    $geocode  = json_decode($geocode );
    echo 'Latitude:' . $geocode ->results[0]->geometry->location->lat;
    echo 'Longitude:' . $geocode ->results[0]->geometry->location->lng;

?>

Remove special character in php

Remove special character in php.


You have a website and in that website you have lot of form for user. user fill many data via that forms. some time user feed special characters that are unreadable. so how to remove that special characters before inserting in data base? here is the few lines of code that will do it.



<?php
$input = "Fóø Bår this is the php form data ?A?B?C?D //\\?......!@#$%^&*()_+"; // input text
$output = iconv("utf-8", "ascii//TRANSLIT//IGNORE", $input);
$output =  preg_replace("/^'|[^A-Za-z0-9\s-]|'$/", '', $output); // Remove utf-8 special characters except blank spaces
echo $output; // Results
?>