Thursday, June 26, 2014

google map latitude longitude php


In this post PHP script convert an address to geocode Latitude/Longitude positioning with Google Maps. In response, you will be get the latitude and longitude details.

For same, you can use following php code.


<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/


$url = "http://maps.google.com/maps/api/geocode/json?address=West+Bridgford&sensor=false®ion=UK";
$result = file_get_contents($url);
$response = json_decode($result, true);

 
$latitude = $response['results'][0]['geometry']['location']['lat'];
$longitude = $response['results'][0]['geometry']['location']['lng'];
 
echo "Latitude: " . $latitude . " Longitude: " . $longitude;



?>

Thursday, May 29, 2014

generate QR code by google api php

In this post we explain you, how you can generate QR code with metadata by google api. You can generat qr code for any link, email, telephone number or text data.

For generate code, you can use following php script:


<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/


function google_qr_code($data, $type = "TXT", $size ='150', $ec='L', $margin='0')  {     
    $types = array("URL" => "http://", "TEL" => "TEL:", "TXT"=>"", "EMAIL" => "MAILTO:");
    if(!in_array($type,array("URL", "TEL", "TXT", "EMAIL")))
    {
        $type = "TXT";
    }
    if (!preg_match('/^'.$types[$type].'/', $data))
    {
        $data = str_replace("\\", "", $types[$type]).$data;
    }
    $ch = curl_init();
    $data = urlencode($data);
    curl_setopt($ch, CURLOPT_URL, 'http://chart.apis.google.com/chart');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'chs='.$size.'x'.$size.'&cht=qr&chld='.$ec.'|'.$margin.'&chl='.$data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);

    $response = curl_exec($ch);

    curl_close($ch);
    return $response;
}

header("Content-type: image/png");

echo google_qr_code("4evertutorials","TXT");
//echo google_qr_code("http://4evertutorials.blogspot.com","URL");
//echo google_qr_code("4evertutorial@gmail.com","EMAIL");
//echo google_qr_code("1234567890","TEL");




?>

Tuesday, May 27, 2014

PHP Expire Session after 30 minutes

In following php script, we explain you that how you can expire session after 30 minutes. Execution a session timeout on your own is that the best answer. Use a straightforward time stamp that denotes the time of the last activity and update it with each request.
CODE USAGE


<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/


if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY'] > 1800)) 
{
    /* last request was more than 30 minutes ago */

    // unset $_SESSION variable for the run-time
    session_unset();     

    // destroy session data in storage
    session_destroy();   

}

// update last activity time stamp
$_SESSION['LAST_ACTIVITY'] = time(); 


// You can also use an additional time stamp to regenerate the session ID periodically to avoid attacks on sessions like session fixation:

if (!isset($_SESSION['CREATED'])) 
{
    $_SESSION['CREATED'] = time();
}
else if (time() - $_SESSION['CREATED'] > 1800)
{
    /* session started more than 30 minutes ago */

    // change session ID for the current session an invalidate old session ID
    session_regenerate_id(true);

    // update creation time
    $_SESSION['CREATED'] = time();  

}

?>

Wednesday, March 26, 2014

check domain name availability with httpapi php


In this post we explain you that how you can check domain name availability using httpapi.com api with php and returns domain name availability status for the requested TLDs. It requires GET HTTP Method. You need following parameters:

auth-userid => your reseller id 
api-key or auth-password => your api code / account password
domain-name => Array of Strings -  that you need to check the availability for
tlds => Array of Strings - TLDs for which the domain name availability needs to be checked
suggest-alternative (optional) => pass "true" if domain name suggestions are required. Default value is false. 

After api call, you will be get the below details in response:

Domain Availability Status (status)

available - domain name available for registration

regthroughus - domain name currently registered through the Registrar whose connection is being used to check the availability of the domain name

regthroughothers - domain name currently registered through a Registrar other than the one whose connection is being used to check the availability of the domain name. If you wish to manage such a domain name through     your Reseller / Registrar Account, you may pass a Domain Transfer API call

unknown - returned, if for some reason, the Registry connections are not available. You should ideally re-check the domain name availability after some time.


For API Call, you can use following php function.


<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/




function Check_Domains()
{

 # API Url: for test=>https://test.httpapi.com , for live=>https://httpapi.com
 $api_url = 'https://test.httpapi.com'; 
 $auth_userid = ''; // reseller unique id
 $api_key = ''; // api-key or reseller password
 
 $domainname1 = 'enter any keyword without space'; // first domain name (example: google)
 $domainname2 = 'keyword2'; // second domain name (example: facebook)

 // top level domains 
 $tld1 = 'com'; 
 $tld2 = 'net';  

   $check_domains = $api_url.'/api/domains/available.json?auth-userid='.$auth_userid.'&api-key='.$api_key.'domain-name='.$domainname1.'&domain-name='.$domainname2.'&tlds='.$tld1.'&tlds='.$tld2;

   $result = @file_get_contents($check_domains);
   $response = json_decode($result, true);
            if($response)
            {   
                return $response;
            }
            else
            {
                return false;
            }


}



?>


Function USAGE

<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/



 
 $_details = Check_Domains();
 
    if($_details)
    {
     echo "
";
        print_r($_details);
        echo "
"; } else { echo ""; } ?>

Monday, March 17, 2014

get sub reseller's promo prices httpapi php


In this post we explain you that how you can get sub-reseller's promo prices using httpapi.com api with php and returns the prices details. It requires GET HTTP Method. You need auth-userid and api-key or auth-password parameters for do that. You will be get the below details in response:

Reseller Id (resellerid)
Product Key (productkey)
Promo Start Time (starttime)
Promo End Time (endtime)
Promo Period (period)
Discounted Price (resellerpriceone)
Standard Price (resellerpricetwo)
Customer Price (customerprice)
Barrrier Price (barrierprice)
Price Applicable to the Sub-Reseller (resellerprice)
Type of Action the Promo is Applicable for (actiontype)
Selling Currency of the Registration Service Provider (serviceprovidersellingcurrency)
Promo Status (isactive)
Whether the Promo can be trickled down the Sub-Reseller chain (istrickleallow)

In case of any errors, a status key with value as ERROR alongwith an error message will be returned. For Promo Prices you can use following function.


<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/


function Promo_Prices()
{

 # API Url: for test=>https://test.httpapi.com , for live=>https://httpapi.com
 $api_url = 'https://test.httpapi.com'; 
 $auth_userid = ''; // reseller unique id
 $api_key = ''; // api-key or reseller password

   $promodetails = $api_url.'/api/resellers/promo-details.json?auth-userid='.$auth_userid.'&api-key='.$api_key;
   $result = @file_get_contents($promodetails);
   $response = json_decode($result, true);
            if($response)
            {   
                return $response;
            }
            else
            {
                return false;
            }


}


?>

Function USAGE

<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/



 
 $prices_details = Promo_Prices();
 
    if($prices_details)
    {
     echo "
";
        print_r($prices_details);
        echo "
"; } else { echo "Invalid request."; } ?>

Thursday, March 13, 2014

how to authenticating a token httpapi php

In this blog post we explain you that how you can authenticates the token generated by the Generate Token method for customer using httpapi.com api and returns the Customer details, if token authenticated. It requires GET HTTP Method. You need auth-userid, api-key or auth-password, and token parameters for process. If the token is authenticated then you will be get the below customer details in response:


Customer Id (customerid)
Customer Username (username)
Reseller Id of the Parent Reseller (resellerid)
Name (name)
Company (company)
Email Address (useremail)
Telephone Number Country Code (telnocc)
Telephone Number (telno)
First line of address of the Customer (address1)
Second line of address of the Customer (address2)
Third line of address of the Customer (address3)
City (city)
State (state)
Country Code (country)
ZIP Code (zip)
Personal Identification Number (pin)
Creation Date (creationdt)
Current Status (customerstatus)
Sales Contact Id (salescontactid)
Language Preference for the Control Panel and Emails (langpref)
Total Receipts (totalreceipts)

In case of any errors, a status key with value as ERROR alongwith an error message will be returned. For Authenticating a Token you can use following function.


<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/

function AUTHENTICATE_TOKEN($token)
{

 # API Url: for test=>https://test.httpapi.com , for live=>https://httpapi.com
 $api_url = 'https://test.httpapi.com'; 
 $auth_userid = ''; // reseller unique id
 $api_key = ''; // api-key or reseller password

   if(isset($token))
   {

   $check_token = $api_url.'/api/customers/authenticate-token.json?auth-userid='.$auth_userid.'&api-key='.$api_key.'&token='.$token;
   $result = @file_get_contents($check_token);
   $response = json_decode($result, true);
   return $response;
 }

 return false;

}

?>

Function USAGE

<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/
 
 $_customer = AUTHENTICATE_TOKEN("token");
 
    if($_customer)
    {

     // Customer details if the token is authenticated

     print_r($_customer);

                              
    }
    else
    {
        echo "Invalid token.";
    }

?>

how to generate a token httpapi php

Generating a Token for customer using httpapi.com api. It requires GET HTTP Method. You need auth-userid, api-key or auth-password, username, passwd and ip parameters for that. You can authenticates a customer by returning an authentication token on successful authentication. In case of any errors, a status key with value as ERROR alongwith an error message will be returned. For this you can use following function. We hope you like that code.


<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/




function GENERATE_TOKEN($username,$passwd)
{

 # API Url: for test=>https://test.httpapi.com , for live=>https://httpapi.com
 $api_url = 'https://test.httpapi.com'; 
 $auth_userid = ''; // reseller unique id
 $api_key = ''; // api-key or reseller password

   if(isset($username) && isset($passwd))
   {

   $client_ip = $_SERVER['REMOTE_ADDR']; 

   $generate_token = $api_url.'/api/customers/generate-token.json?auth-userid='.$auth_userid.'&api-key='.$api_key.'&username='.urlencode($username).'&passwd='.urlencode($passwd).'&ip='.$client_ip;
   $result = @file_get_contents($generate_token);
   $token = json_decode($result, true);
   return $token;

 }

 return false;

}


?>

Function USAGE

<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.in/
*/



 $_token = GENERATE_TOKEN("send_username","send_passwd");
 
    if($_token)
    {

     // token successful authentication
     // after generating a token you need to Authenticating a Token this will be our next post
                              
    }
    else
    {
        echo "Invalid Username or Password.";
    }


?>

 

© 2014 4everTutorials. All rights resevered.

Back To Top