Showing posts with label file_get_contents. Show all posts
Showing posts with label file_get_contents. Show all posts

Friday, May 29, 2015

Generate and save file in directory using PHP

4everTutorials

In this lesson we will see how to generate file and save into new directory using PHP. So we will generate a HTML, PHP or any other type of file and save it into a newly created or existed directory.

Step 1: At first we have to select an existing directory or create a new directory by using mkdir() function.


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

$dir_path = "depth1/depth2/depth3";
 
mkdir($dir_path, 0777, true);

?>

Here, $dir_path is the path to the expected directory/folder of your hard drive.
And ’0777′ is the default permission of the folder/file (widest possible access).

So, the file will be located in this directory: current_directory/depth1/depth2/depth3

But if you want to create the folder outside the current directory, then use “../” for each level you want to go back for the new directory.

For example, if your current directory is “C:\xampp\htdocs\cd” and you want to create the new folder inside “xampp” folder then you have to write like the following-


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

$dir_path = "../../test";
 
mkdir($dir_path, 0777, true);

?>


So, path for the new directory will be “C:\xampp\test”.

Step 2: After creating the directory simply put the generated file to the directory by using file_put_contents() function.

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

file_put_contents($dir_path."/name-of-file.html", $content);
file_put_contents($dir_path."/name-of-file.php", $content);
file_put_contents($dir_path."/name-of-file.txt", $content);

?>

Here, name-of-file is the expected name of your file and $content is the the data that you want to save in the file.

Wednesday, September 3, 2014

Using Google PageSpeed Insights API with php

In this post we learn how to analyze websites using google pagespeed insights api with PHP. First of all you need to acquire an API key: 




1) Go to the Google Developers Console

2) Select a project, or create a new one. 

3) In the sidebar on the left, expand APIs & auth. Next, click APIs. In the list of APIs, make sure the status is ON for the PageSpeed Insights API. 

4) In the sidebar on the left, select Credentials

5) This API supports two types of credentials. You need only Public API access: A request that does not provide an OAuth 2.0 token must send an API key. The key identifies your project and provides API access, quota, and reports.

To create an API key, click Create new Key and select the appropriate key type. Enter the additional information required for that key type and click Create.

Replace "API_KEY" with your ones in following php function.


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

function checkPageSpeed($url){  
  if (function_exists('file_get_contents')) {  
    $result = @file_get_contents($url);  
  }  
  if ($result == '') {  
    $ch = curl_init();  
    $timeout = 60;  
    curl_setopt($ch, CURLOPT_URL, $url);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);  
    $result = curl_exec($ch);  
    curl_close($ch);  
  }  

  return $result;  
}

?>

HOW TO USE CODE
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/

$myKEY = "API_KEY";
$url = "http://4evertutorials.blogspot.com";
$url_req = 'https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url='.$url.'&key='.$myKEY;
$results = checkPageSpeed($url_req);
echo '
';
print_r(json_decode($results,true)); 
echo '
'; ?>

Friday, August 29, 2014

php linkedin company search and group search


Hello programmers, here is simple php code to extract companies and groups details which has linkedin profile. You need only pass search keyword in URL for companies or groups to get their details. It will return a JSON response with id, head line, logo url, displayname, subline, profile url

For example a search of "google" would be
http://www.linkedin.com/ta/federator?query=google&types=company,group,sitefeature

Please keep in mind linkedin API does not seem to have this feature. If you need linkedin API, please feel free to read through the documentation here.

Usage of code

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

$companies = file_get_contents('http://www.linkedin.com/ta/federator?query=google&types=company,group,sitefeature');

$results = json_decode($companies,true);

echo "
";
print_r($results);
echo "
"; ?>
Output returns
 
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/

Array
(
    [company] => Array
        (
            [resultList] => Array
                (
                    [0] => Array
                        (
                            [id] => 1441
                            [headLine] => Google
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/3/000/062/2ff/080cae8.png
                            [displayName] => Google
                            [subLine] => Internet; 10,001+ employees
                            [url] => http://www.linkedin.com/company/1441
                        )

                    [1] => Array
                        (
                            [id] => 2486941
                            [headLine] => Google SEO (Page 1 Google)
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/4/000/139/37d/3d91dea.png
                            [displayName] => Google SEO (Page 1 Google)
                            [subLine] => Internet; 1-10 employees
                            [url] => http://www.linkedin.com/company/2486941
                        )

                    [2] => Array
                        (
                            [id] => 3017073
                            [headLine] => Google / Titan Aerospace
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/6/000/220/1c0/16d865f.png
                            [displayName] => Google / Titan Aerospace
                            [subLine] => Airlines/Aviation; 11-50 employees
                            [url] => http://www.linkedin.com/company/3017073
                        )

                    [3] => Array
                        (
                            [id] => 621453
                            [headLine] => Wildfire by Google
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/2/000/18f/281/144bd3b.png
                            [displayName] => Wildfire by Google
                            [subLine] => Computer Software; 201-500 employees
                            [url] => http://www.linkedin.com/company/621453
                        )

                    [4] => Array
                        (
                            [id] => 1176352
                            [headLine] => Geoambiente - Google Enterprise Partner
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/8/005/056/2ff/10d57ab.png
                            [displayName] => Geoambiente - Google Enterprise Partner
                            [subLine] => Information Technology and Services; 51-200 employees
                            [url] => http://www.linkedin.com/company/1176352
                        )

                    [5] => Array
                        (
                            [id] => 791962
                            [headLine] => Adometry by Google
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/1/000/18e/2ac/0e9319c.png
                            [displayName] => Adometry by Google
                            [subLine] => Marketing and Advertising; 51-200 employees
                            [url] => http://www.linkedin.com/company/791962
                        )

                    [6] => Array
                        (
                            [id] => 9863
                            [headLine] => ITA Software by Google
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/3/000/0ae/217/0b991b7.png
                            [displayName] => ITA Software by Google
                            [subLine] => Computer Software; 10,001+ employees
                            [url] => http://www.linkedin.com/company/9863
                        )

                    [7] => Array
                        (
                            [id] => 2871869
                            [headLine] => Google Account Managers
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/7/000/1e3/199/293d5b2.png
                            [displayName] => Google Account Managers
                            [subLine] => Marketing and Advertising; 1-10 employees
                            [url] => http://www.linkedin.com/company/2871869
                        )

                    [8] => Array
                        (
                            [id] => 2321528
                            [headLine] => Google AdWords Certified
                            [displayName] => Google AdWords Certified
                            [subLine] => Marketing and Advertising; Myself Only
                            [url] => http://www.linkedin.com/company/2321528
                        )

                    [9] => Array
                        (
                            [id] => 2287804
                            [headLine] => Googlelearn
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/3/000/0da/002/023b4ef.png
                            [displayName] => Googlelearn
                            [subLine] => Education Management; Myself Only
                            [url] => http://www.linkedin.com/company/2287804
                        )

                    [10] => Array
                        (
                            [id] => 3215165
                            [headLine] => Squared Online - a Google / HLC Partnership
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/6/005/056/2d9/33a677d.png
                            [displayName] => Squared Online - a Google / HLC Partnership
                            [subLine] => E-Learning; 11-50 employees
                            [url] => http://www.linkedin.com/company/3215165
                        )

                    [11] => Array
                        (
                            [id] => 2336657
                            [headLine] => Google Apps Authorized Reseller | Bmeet.it
                            [displayName] => Google Apps Authorized Reseller | Bmeet.it
                            [subLine] => Information Technology and Services; Myself Only
                            [url] => http://www.linkedin.com/company/2336657
                        )

                    [12] => Array
                        (
                            [id] => 762501
                            [headLine] => Bump Technologies (acquired by Google)
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/4/000/14c/1a4/3079095.png
                            [displayName] => Bump Technologies (acquired by Google)
                            [subLine] => Wireless; 11-50 employees
                            [url] => http://www.linkedin.com/company/762501
                        )

                    [13] => Array
                        (
                            [id] => 2093403
                            [headLine] => Video Marketing, VSEO, Google Places Optimization, Page One of Google at Cary Duke
                            [displayName] => Video Marketing, VSEO, Google Places Optimization, Page One of Google at Cary Duke
                            [subLine] => Marketing and Advertising; Myself Only
                            [url] => http://www.linkedin.com/company/2093403
                        )

                    [14] => Array
                        (
                            [id] => 2372226
                            [headLine] => Focus BC - EMEA Google Enterprise Partner
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/1/005/03d/3d5/1f046f8.png
                            [displayName] => Focus BC - EMEA Google Enterprise Partner
                            [subLine] => Management Consulting; 11-50 employees
                            [url] => http://www.linkedin.com/company/2372226
                        )

                    [15] => Array
                        (
                            [id] => 3489855
                            [headLine] => PANOSUR - Google Maps Business Views certified Photographer
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/1/005/081/09e/08920d6.png
                            [displayName] => PANOSUR - Google Maps Business Views certified Photographer
                            [subLine] => Photography; 1-10 employees
                            [url] => http://www.linkedin.com/company/3489855
                        )

                    [16] => Array
                        (
                            [id] => 3361424
                            [headLine] => Arroba System - Google Apps Authorized Reseller
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/7/005/019/37e/1933930.png
                            [displayName] => Arroba System - Google Apps Authorized Reseller
                            [subLine] => Internet; 11-50 employees
                            [url] => http://www.linkedin.com/company/3361424
                        )

                    [17] => Array
                        (
                            [id] => 978865
                            [headLine] => WIMM Labs (acquired by Google)
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/1/000/071/203/0b3d11a.png
                            [displayName] => WIMM Labs (acquired by Google)
                            [subLine] => Consumer Electronics; 11-50 employees
                            [url] => http://www.linkedin.com/company/978865
                        )

                    [18] => Array
                        (
                            [id] => 3081545
                            [headLine] => Google Virksomhedsbilleder: Google går indenfor i din virksomhed
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/2/000/241/1af/2f5a4b8.png
                            [displayName] => Google Virksomhedsbilleder: Google går indenfor i din virksomhed
                            [subLine] => Photography; Myself Only
                            [url] => http://www.linkedin.com/company/3081545
                        )

                    [19] => Array
                        (
                            [id] => 3200505
                            [headLine] => Google International
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/5/005/042/1fa/3d1c00e.png
                            [displayName] => Google International
                            [subLine] => Legal Services; 11-50 employees
                            [url] => http://www.linkedin.com/company/3200505
                        )

                )

        )

    [group] => Array
        (
            [resultList] => Array
                (
                    [0] => Array
                        (
                            [id] => 4248784
                            [headLine] => Google
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/3/000/128/301/196fb6a.png
                            [displayName] => Google
                            [subLine] => 
                            [url] => http://www.linkedin.com/groups?gid=4248784&mostPopular=
                        )

                    [1] => Array
                        (
                            [id] => 4006283
                            [headLine] => GOOGLE+
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/3/000/0d7/077/064bc0b.png
                            [displayName] => GOOGLE+
                            [subLine] => 
                            [url] => http://www.linkedin.com/groups?gid=4006283&mostPopular=
                        )

                    [2] => Array
                        (
                            [id] => 76373
                            [headLine] => Google Android
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/1/000/01f/3e7/2fd0a55.png
                            [displayName] => Google Android
                            [subLine] => 
                            [url] => http://www.linkedin.com/groups?gid=76373&mostPopular=
                        )

                    [3] => Array
                        (
                            [id] => 2930475
                            [headLine] => Google Universe : Jobs, Tools, Trends and Galaxies of Ideas
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/2/000/057/1c8/2bc17fb.png
                            [displayName] => Google Universe : Jobs, Tools, Trends and Galaxies of Ideas
                            [subLine] => 
                            [url] => http://www.linkedin.com/groups?gid=2930475&mostPopular=
                        )

                    [4] => Array
                        (
                            [id] => 1604367
                            [headLine] => Google Analytics
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/1/000/01f/0e8/326ef60.png
                            [displayName] => Google Analytics
                            [subLine] => 
                            [url] => http://www.linkedin.com/groups?gid=1604367&mostPopular=
                        )

                    [5] => Array
                        (
                            [id] => 37724
                            [headLine] => Google Adwords Qualified Individuals
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/3/000/000/2fa/137b4fa.png
                            [displayName] => Google Adwords Qualified Individuals
                            [subLine] => 
                            [url] => http://www.linkedin.com/groups?gid=37724&mostPopular=
                        )

                    [6] => Array
                        (
                            [id] => 85376
                            [headLine] => Google Apps
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/2/000/007/2c8/1b2d372.png
                            [displayName] => Google Apps
                            [subLine] => 
                            [url] => http://www.linkedin.com/groups?gid=85376&mostPopular=
                        )

                    [7] => Array
                        (
                            [id] => 1825251
                            [headLine] => Google Professional Network
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/1/005/020/06c/2dedc76.png
                            [displayName] => Google Professional Network
                            [subLine] => 
                            [url] => http://www.linkedin.com/groups?gid=1825251&mostPopular=
                        )

                    [8] => Array
                        (
                            [id] => 107462
                            [headLine] => Google APPS users
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/1/000/0a8/310/195dc10.png
                            [displayName] => Google APPS users
                            [subLine] => 
                            [url] => http://www.linkedin.com/groups?gid=107462&mostPopular=
                        )

                    [9] => Array
                        (
                            [id] => 3190679
                            [headLine] => Google Adwords SEO SEM (Search Engine Optimization & Internet Marketing)
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/3/000/063/225/3d1ab3b.png
                            [displayName] => Google Adwords SEO SEM (Search Engine Optimization & Internet Marketing)
                            [subLine] => 
                            [url] => http://www.linkedin.com/groups?gid=3190679&mostPopular=
                        )

                    [10] => Array
                        (
                            [id] => 3066064
                            [headLine] => Google Android TV
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/4/000/132/34b/148cc74.png
                            [displayName] => Google Android TV
                            [subLine] => 
                            [url] => http://www.linkedin.com/groups?gid=3066064&mostPopular=
                        )

                    [11] => Array
                        (
                            [id] => 95911
                            [headLine] => Google Adwords
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/1/000/008/327/0b214eb.png
                            [displayName] => Google Adwords
                            [subLine] => 
                            [url] => http://www.linkedin.com/groups?gid=95911&mostPopular=
                        )

                    [12] => Array
                        (
                            [id] => 36431
                            [headLine] => Google Alumni
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/1/000/00c/33f/0724411.png
                            [displayName] => Google Alumni
                            [subLine] => 
                            [url] => http://www.linkedin.com/groups?gid=36431&mostPopular=
                        )

                    [13] => Array
                        (
                            [id] => 128878
                            [headLine] => Google App Engine Developers
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/1/000/00b/325/2709731.png
                            [displayName] => Google App Engine Developers
                            [subLine] => 
                            [url] => http://www.linkedin.com/groups?gid=128878&mostPopular=
                        )

                    [14] => Array
                        (
                            [id] => 1840064
                            [headLine] => Google Analytics Qualified Individuals
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/2/000/01e/38e/1919a0b.png
                            [displayName] => Google Analytics Qualified Individuals
                            [subLine] => 
                            [url] => http://www.linkedin.com/groups?gid=1840064&mostPopular=
                        )

                    [15] => Array
                        (
                            [id] => 4022728
                            [headLine] => Google Plus Marketing
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/1/000/0e5/2dc/34faf4e.png
                            [displayName] => Google Plus Marketing
                            [subLine] => 
                            [url] => http://www.linkedin.com/groups?gid=4022728&mostPopular=
                        )

                    [16] => Array
                        (
                            [id] => 1873841
                            [headLine] => Google Apps Solution Providers
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/3/000/020/345/2803f2e.png
                            [displayName] => Google Apps Solution Providers
                            [subLine] => 
                            [url] => http://www.linkedin.com/groups?gid=1873841&mostPopular=
                        )

                    [17] => Array
                        (
                            [id] => 2768916
                            [headLine] => Google+ and Google Products for Nonprofit Organizations
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/1/000/080/2fd/0d176f3.png
                            [displayName] => Google+ and Google Products for Nonprofit Organizations
                            [subLine] => 
                            [url] => http://www.linkedin.com/groups?gid=2768916&mostPopular=
                        )

                    [18] => Array
                        (
                            [id] => 93548
                            [headLine] => Google Adwords Professional Group
                            [displayName] => Google Adwords Professional Group
                            [subLine] => 
                            [url] => http://www.linkedin.com/groups?gid=93548&mostPopular=
                        )

                    [19] => Array
                        (
                            [id] => 1772976
                            [headLine] => Google SEO en Zoekmachine Professionals Nederland
                            [imageUrl] => http://m.c.lnkd.licdn.com/mpr/mpr/shrink_40_40/p/4/005/03b/12f/3d921f3.png
                            [displayName] => Google SEO en Zoekmachine Professionals Nederland
                            [subLine] => 
                            [url] => http://www.linkedin.com/groups?gid=1772976&mostPopular=
                        )

                )

        )

)


?>

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;



?>

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