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=
                        )

                )

        )

)


?>

Saturday, August 23, 2014

php capture website screenshot script

In this post we learn how to take websites screenshots very easily in PHP using Grabz.it 's API. First of all you need to create grabz.it account  to get API keys (APPLICATION KEY and APPLICATION SECRET) . Replace "APPLICATION KEY", "APPLICATION SECRET" with the values from your account. The best way to put website screenshots into your PHP application is by using our simple PHP API.
<?php

/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/
include("GrabzItClient.class.php");

$grabzIt = new GrabzItClient("APPLICATION KEY", "APPLICATION SECRET");// Replace "APPLICATION KEY", "APPLICATION SECRET" with the values from your account!

// To take a image screenshot
$grabzIt->SetImageOptions("http://www.google.com");     
// Or to take a PDF screenshot
$grabzIt->SetPDFOptions("http://www.google.com");
// Or to capture table(s)
$grabzIt->SetTableOptions("http://www.google.com");

?>

Above code is used to create class object with your account API key and secret after creating object we are calling 3 different methods SetImageOptions used to capture image of given page output, SetPDFOptions used to create PDF of given url and SetTableOptions is used to extract tables from the web page.

More Options

There are many more options including; configuring the browser height, browser width, screenshot height, screenshot width, the delay before a screenshot is taken and the image format of the screenshot. For all these options please see the Client documentation.


Wednesday, August 20, 2014

php image data uri

To create data uri in php, read image (png, gif, jpg) file with file_get_contents and convert it to base64 using base64_encode. Using Data URIs you can reduce network requests. But, Please keep in mind if you plan on using data URIs, they are not supported by ie7 and lower.
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/


function createDataURI($image,$mime='') {

    $finfo = new finfo(FILEINFO_MIME_TYPE);

    $mime = $finfo->buffer(file_get_contents($image));

    return 'data:'.$mime.';base64,'.base64_encode(file_get_contents($image));
}

?>

How to  create data uri

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


echo '';

?>

best method to encrypt or decrypt in php

Here is a safe encrypt and decrypt function for php developer. You can Encrypt and Decrypt using md5. The md5() function calculates the MD5 hash of a string. md5() and sha1() provides the same functinality of encryption in php but they differ in a simple way that md5() generates 32 characters of encrypted string which sha1() generates same of 40 characters.

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


function encrypt_decrypt($action, $string) {
   $output = false;

   $key = 'My strong random secret key';

   // initialization vector 
   $iv = md5(md5($key));

   if( $action == 'encrypt' ) {
       $output = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, $iv);
       $output = base64_encode($output);
   }
   else if( $action == 'decrypt' ){
       $output = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($string), MCRYPT_MODE_CBC, $iv);
       $output = rtrim($output, "");
   }
   return $output;
}

?>

How to use encrypt or decrypt code:
 
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/


$plain_txt = "This is my plain text";
$encrypted_txt = encrypt_decrypt('encrypt', $plain_txt);
echo "Encrypted = $encrypted_txt\n";
echo "
"; $decrypted_txt = encrypt_decrypt('decrypt', $encrypted_txt); echo "Decrypted = $decrypted_txt\n"; ?>

Monday, August 11, 2014

get country from alpha-2 code in php

ISO 3166-1 alpha-2 codes are two-letter country codes defined in ISO 3166-1, part of the ISO 3166 standard published by the International Organization for Standardization (ISO), to represent countries, dependent territories, and special areas of geographical interest. In this post we use php to get country name from alpha-2 code of country.

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



function getCountryName($code)
{
    $country = '';
    if( $code == 'AF' ) $country = 'Afghanistan';
    if( $code == 'AX' ) $country = 'Aland Islands';
    if( $code == 'AL' ) $country = 'Albania';
    if( $code == 'DZ' ) $country = 'Algeria';
    if( $code == 'AS' ) $country = 'American Samoa';
    if( $code == 'AD' ) $country = 'Andorra';
    if( $code == 'AO' ) $country = 'Angola';
    if( $code == 'AI' ) $country = 'Anguilla';
    if( $code == 'AQ' ) $country = 'Antarctica';
    if( $code == 'AG' ) $country = 'Antigua and Barbuda';
    if( $code == 'AR' ) $country = 'Argentina';
    if( $code == 'AM' ) $country = 'Armenia';
    if( $code == 'AW' ) $country = 'Aruba';
    if( $code == 'AU' ) $country = 'Australia';
    if( $code == 'AT' ) $country = 'Austria';
    if( $code == 'AZ' ) $country = 'Azerbaijan';
    if( $code == 'BS' ) $country = 'Bahamas the';
    if( $code == 'BH' ) $country = 'Bahrain';
    if( $code == 'BD' ) $country = 'Bangladesh';
    if( $code == 'BB' ) $country = 'Barbados';
    if( $code == 'BY' ) $country = 'Belarus';
    if( $code == 'BE' ) $country = 'Belgium';
    if( $code == 'BZ' ) $country = 'Belize';
    if( $code == 'BJ' ) $country = 'Benin';
    if( $code == 'BM' ) $country = 'Bermuda';
    if( $code == 'BT' ) $country = 'Bhutan';
    if( $code == 'BO' ) $country = 'Bolivia';
    if( $code == 'BA' ) $country = 'Bosnia and Herzegovina';
    if( $code == 'BW' ) $country = 'Botswana';
    if( $code == 'BV' ) $country = 'Bouvet Island (Bouvetoya)';
    if( $code == 'BR' ) $country = 'Brazil';
    if( $code == 'IO' ) $country = 'British Indian Ocean Territory (Chagos Archipelago)';
    if( $code == 'VG' ) $country = 'British Virgin Islands';
    if( $code == 'BN' ) $country = 'Brunei Darussalam';
    if( $code == 'BG' ) $country = 'Bulgaria';
    if( $code == 'BF' ) $country = 'Burkina Faso';
    if( $code == 'BI' ) $country = 'Burundi';
    if( $code == 'KH' ) $country = 'Cambodia';
    if( $code == 'CM' ) $country = 'Cameroon';
    if( $code == 'CA' ) $country = 'Canada';
    if( $code == 'CV' ) $country = 'Cape Verde';
    if( $code == 'KY' ) $country = 'Cayman Islands';
    if( $code == 'CF' ) $country = 'Central African Republic';
    if( $code == 'TD' ) $country = 'Chad';
    if( $code == 'CL' ) $country = 'Chile';
    if( $code == 'CN' ) $country = 'China';
    if( $code == 'CX' ) $country = 'Christmas Island';
    if( $code == 'CC' ) $country = 'Cocos (Keeling) Islands';
    if( $code == 'CO' ) $country = 'Colombia';
    if( $code == 'KM' ) $country = 'Comoros the';
    if( $code == 'CD' ) $country = 'Congo';
    if( $code == 'CG' ) $country = 'Congo the';
    if( $code == 'CK' ) $country = 'Cook Islands';
    if( $code == 'CR' ) $country = 'Costa Rica';
    if( $code == 'CI' ) $country = 'Cote d\'Ivoire';
    if( $code == 'HR' ) $country = 'Croatia';
    if( $code == 'CU' ) $country = 'Cuba';
    if( $code == 'CY' ) $country = 'Cyprus';
    if( $code == 'CZ' ) $country = 'Czech Republic';
    if( $code == 'DK' ) $country = 'Denmark';
    if( $code == 'DJ' ) $country = 'Djibouti';
    if( $code == 'DM' ) $country = 'Dominica';
    if( $code == 'DO' ) $country = 'Dominican Republic';
    if( $code == 'EC' ) $country = 'Ecuador';
    if( $code == 'EG' ) $country = 'Egypt';
    if( $code == 'SV' ) $country = 'El Salvador';
    if( $code == 'GQ' ) $country = 'Equatorial Guinea';
    if( $code == 'ER' ) $country = 'Eritrea';
    if( $code == 'EE' ) $country = 'Estonia';
    if( $code == 'ET' ) $country = 'Ethiopia';
    if( $code == 'FO' ) $country = 'Faroe Islands';
    if( $code == 'FK' ) $country = 'Falkland Islands (Malvinas)';
    if( $code == 'FJ' ) $country = 'Fiji the Fiji Islands';
    if( $code == 'FI' ) $country = 'Finland';
    if( $code == 'FR' ) $country = 'France, French Republic';
    if( $code == 'GF' ) $country = 'French Guiana';
    if( $code == 'PF' ) $country = 'French Polynesia';
    if( $code == 'TF' ) $country = 'French Southern Territories';
    if( $code == 'GA' ) $country = 'Gabon';
    if( $code == 'GM' ) $country = 'Gambia the';
    if( $code == 'GE' ) $country = 'Georgia';
    if( $code == 'DE' ) $country = 'Germany';
    if( $code == 'GH' ) $country = 'Ghana';
    if( $code == 'GI' ) $country = 'Gibraltar';
    if( $code == 'GR' ) $country = 'Greece';
    if( $code == 'GL' ) $country = 'Greenland';
    if( $code == 'GD' ) $country = 'Grenada';
    if( $code == 'GP' ) $country = 'Guadeloupe';
    if( $code == 'GU' ) $country = 'Guam';
    if( $code == 'GT' ) $country = 'Guatemala';
    if( $code == 'GG' ) $country = 'Guernsey';
    if( $code == 'GN' ) $country = 'Guinea';
    if( $code == 'GW' ) $country = 'Guinea-Bissau';
    if( $code == 'GY' ) $country = 'Guyana';
    if( $code == 'HT' ) $country = 'Haiti';
    if( $code == 'HM' ) $country = 'Heard Island and McDonald Islands';
    if( $code == 'VA' ) $country = 'Holy See (Vatican City State)';
    if( $code == 'HN' ) $country = 'Honduras';
    if( $code == 'HK' ) $country = 'Hong Kong';
    if( $code == 'HU' ) $country = 'Hungary';
    if( $code == 'IS' ) $country = 'Iceland';
    if( $code == 'IN' ) $country = 'India';
    if( $code == 'ID' ) $country = 'Indonesia';
    if( $code == 'IR' ) $country = 'Iran';
    if( $code == 'IQ' ) $country = 'Iraq';
    if( $code == 'IE' ) $country = 'Ireland';
    if( $code == 'IM' ) $country = 'Isle of Man';
    if( $code == 'IL' ) $country = 'Israel';
    if( $code == 'IT' ) $country = 'Italy';
    if( $code == 'JM' ) $country = 'Jamaica';
    if( $code == 'JP' ) $country = 'Japan';
    if( $code == 'JE' ) $country = 'Jersey';
    if( $code == 'JO' ) $country = 'Jordan';
    if( $code == 'KZ' ) $country = 'Kazakhstan';
    if( $code == 'KE' ) $country = 'Kenya';
    if( $code == 'KI' ) $country = 'Kiribati';
    if( $code == 'KP' ) $country = 'Korea';
    if( $code == 'KR' ) $country = 'Korea';
    if( $code == 'KW' ) $country = 'Kuwait';
    if( $code == 'KG' ) $country = 'Kyrgyz Republic';
    if( $code == 'LA' ) $country = 'Lao';
    if( $code == 'LV' ) $country = 'Latvia';
    if( $code == 'LB' ) $country = 'Lebanon';
    if( $code == 'LS' ) $country = 'Lesotho';
    if( $code == 'LR' ) $country = 'Liberia';
    if( $code == 'LY' ) $country = 'Libyan Arab Jamahiriya';
    if( $code == 'LI' ) $country = 'Liechtenstein';
    if( $code == 'LT' ) $country = 'Lithuania';
    if( $code == 'LU' ) $country = 'Luxembourg';
    if( $code == 'MO' ) $country = 'Macao';
    if( $code == 'MK' ) $country = 'Macedonia';
    if( $code == 'MG' ) $country = 'Madagascar';
    if( $code == 'MW' ) $country = 'Malawi';
    if( $code == 'MY' ) $country = 'Malaysia';
    if( $code == 'MV' ) $country = 'Maldives';
    if( $code == 'ML' ) $country = 'Mali';
    if( $code == 'MT' ) $country = 'Malta';
    if( $code == 'MH' ) $country = 'Marshall Islands';
    if( $code == 'MQ' ) $country = 'Martinique';
    if( $code == 'MR' ) $country = 'Mauritania';
    if( $code == 'MU' ) $country = 'Mauritius';
    if( $code == 'YT' ) $country = 'Mayotte';
    if( $code == 'MX' ) $country = 'Mexico';
    if( $code == 'FM' ) $country = 'Micronesia';
    if( $code == 'MD' ) $country = 'Moldova';
    if( $code == 'MC' ) $country = 'Monaco';
    if( $code == 'MN' ) $country = 'Mongolia';
    if( $code == 'ME' ) $country = 'Montenegro';
    if( $code == 'MS' ) $country = 'Montserrat';
    if( $code == 'MA' ) $country = 'Morocco';
    if( $code == 'MZ' ) $country = 'Mozambique';
    if( $code == 'MM' ) $country = 'Myanmar';
    if( $code == 'NA' ) $country = 'Namibia';
    if( $code == 'NR' ) $country = 'Nauru';
    if( $code == 'NP' ) $country = 'Nepal';
    if( $code == 'AN' ) $country = 'Netherlands Antilles';
    if( $code == 'NL' ) $country = 'Netherlands the';
    if( $code == 'NC' ) $country = 'New Caledonia';
    if( $code == 'NZ' ) $country = 'New Zealand';
    if( $code == 'NI' ) $country = 'Nicaragua';
    if( $code == 'NE' ) $country = 'Niger';
    if( $code == 'NG' ) $country = 'Nigeria';
    if( $code == 'NU' ) $country = 'Niue';
    if( $code == 'NF' ) $country = 'Norfolk Island';
    if( $code == 'MP' ) $country = 'Northern Mariana Islands';
    if( $code == 'NO' ) $country = 'Norway';
    if( $code == 'OM' ) $country = 'Oman';
    if( $code == 'PK' ) $country = 'Pakistan';
    if( $code == 'PW' ) $country = 'Palau';
    if( $code == 'PS' ) $country = 'Palestinian Territory';
    if( $code == 'PA' ) $country = 'Panama';
    if( $code == 'PG' ) $country = 'Papua New Guinea';
    if( $code == 'PY' ) $country = 'Paraguay';
    if( $code == 'PE' ) $country = 'Peru';
    if( $code == 'PH' ) $country = 'Philippines';
    if( $code == 'PN' ) $country = 'Pitcairn Islands';
    if( $code == 'PL' ) $country = 'Poland';
    if( $code == 'PT' ) $country = 'Portugal, Portuguese Republic';
    if( $code == 'PR' ) $country = 'Puerto Rico';
    if( $code == 'QA' ) $country = 'Qatar';
    if( $code == 'RE' ) $country = 'Reunion';
    if( $code == 'RO' ) $country = 'Romania';
    if( $code == 'RU' ) $country = 'Russian Federation';
    if( $code == 'RW' ) $country = 'Rwanda';
    if( $code == 'BL' ) $country = 'Saint Barthelemy';
    if( $code == 'SH' ) $country = 'Saint Helena';
    if( $code == 'KN' ) $country = 'Saint Kitts and Nevis';
    if( $code == 'LC' ) $country = 'Saint Lucia';
    if( $code == 'MF' ) $country = 'Saint Martin';
    if( $code == 'PM' ) $country = 'Saint Pierre and Miquelon';
    if( $code == 'VC' ) $country = 'Saint Vincent and the Grenadines';
    if( $code == 'WS' ) $country = 'Samoa';
    if( $code == 'SM' ) $country = 'San Marino';
    if( $code == 'ST' ) $country = 'Sao Tome and Principe';
    if( $code == 'SA' ) $country = 'Saudi Arabia';
    if( $code == 'SN' ) $country = 'Senegal';
    if( $code == 'RS' ) $country = 'Serbia';
    if( $code == 'SC' ) $country = 'Seychelles';
    if( $code == 'SL' ) $country = 'Sierra Leone';
    if( $code == 'SG' ) $country = 'Singapore';
    if( $code == 'SK' ) $country = 'Slovakia (Slovak Republic)';
    if( $code == 'SI' ) $country = 'Slovenia';
    if( $code == 'SB' ) $country = 'Solomon Islands';
    if( $code == 'SO' ) $country = 'Somalia, Somali Republic';
    if( $code == 'ZA' ) $country = 'South Africa';
    if( $code == 'GS' ) $country = 'South Georgia and the South Sandwich Islands';
    if( $code == 'ES' ) $country = 'Spain';
    if( $code == 'LK' ) $country = 'Sri Lanka';
    if( $code == 'SD' ) $country = 'Sudan';
    if( $code == 'SR' ) $country = 'Suriname';
    if( $code == 'SJ' ) $country = 'Svalbard & Jan Mayen Islands';
    if( $code == 'SZ' ) $country = 'Swaziland';
    if( $code == 'SE' ) $country = 'Sweden';
    if( $code == 'CH' ) $country = 'Switzerland, Swiss Confederation';
    if( $code == 'SY' ) $country = 'Syrian Arab Republic';
    if( $code == 'TW' ) $country = 'Taiwan';
    if( $code == 'TJ' ) $country = 'Tajikistan';
    if( $code == 'TZ' ) $country = 'Tanzania';
    if( $code == 'TH' ) $country = 'Thailand';
    if( $code == 'TL' ) $country = 'Timor-Leste';
    if( $code == 'TG' ) $country = 'Togo';
    if( $code == 'TK' ) $country = 'Tokelau';
    if( $code == 'TO' ) $country = 'Tonga';
    if( $code == 'TT' ) $country = 'Trinidad and Tobago';
    if( $code == 'TN' ) $country = 'Tunisia';
    if( $code == 'TR' ) $country = 'Turkey';
    if( $code == 'TM' ) $country = 'Turkmenistan';
    if( $code == 'TC' ) $country = 'Turks and Caicos Islands';
    if( $code == 'TV' ) $country = 'Tuvalu';
    if( $code == 'UG' ) $country = 'Uganda';
    if( $code == 'UA' ) $country = 'Ukraine';
    if( $code == 'AE' ) $country = 'United Arab Emirates';
    if( $code == 'GB' ) $country = 'United Kingdom';
    if( $code == 'US' ) $country = 'United States of America';
    if( $code == 'UM' ) $country = 'United States Minor Outlying Islands';
    if( $code == 'VI' ) $country = 'United States Virgin Islands';
    if( $code == 'UY' ) $country = 'Uruguay, Eastern Republic of';
    if( $code == 'UZ' ) $country = 'Uzbekistan';
    if( $code == 'VU' ) $country = 'Vanuatu';
    if( $code == 'VE' ) $country = 'Venezuela';
    if( $code == 'VN' ) $country = 'Vietnam';
    if( $code == 'WF' ) $country = 'Wallis and Futuna';
    if( $code == 'EH' ) $country = 'Western Sahara';
    if( $code == 'YE' ) $country = 'Yemen';
    if( $code == 'ZM' ) $country = 'Zambia';
    if( $code == 'ZW' ) $country = 'Zimbabwe';
    if( $country == '') $country = $code;
    return $country;
}


?>


Usage:-


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

// for get United States of America use following syntax
echo getCountryName('US');



?>

Create sitemap.xml.gz using PHP

In this in post we learn how to generate compressed XML sitemap with php. If some reason Apache does not support gzipping - old version, modules not enabled etc, you can use PHP to generate the compressed XML sitemap. PHP comes with a module of its own to generate gzipped content. Execute phpinfo() and look for the strings "deflate" and "gzip", if you found them, you are ready to start outputting compressed content right away, all you have to do is send the header header('content-type: application/x-gzip') to send the content as a gzipped file.

Following example show you how you can do that:

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

$file_name = 'sitemap.xml';
header('content-type: application/x-gzip');
header('Content-Disposition: attachment; filename="'.$file_name.'.gz"');
$data = "dynamic XML sitemap string goes here";
$gzdata = gzencode($data, 9);
echo $gzdata;

?>

Wednesday, August 6, 2014

extract meta tag content in php

In last post we add script about grab webpage title tag and description , keywords meta tag content. But now this post we explain that how programmer can extract all the meta tags information from specific webpage with get_meta_tags and returns an array.
 


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


function get_meta_data($url, $searchkey='') {   
    $data = get_meta_tags($url);    // get the meta data in an array
    foreach($data as $key => $value) {
        if(mb_detect_encoding($value, 'UTF-8, ISO-8859-1', true) != 'ISO-8859-1') {    // check whether the content is UTF-8 or ISO-8859-1
            $value = utf8_decode($value);    // if UTF-8 decode it
        }
        $value = strtr($value, get_html_translation_table(HTML_ENTITIES));    // mask the content
        if($searchkey != '') {    // if only one meta tag is in demand e.g. 'description'
            if($key == $searchkey) {
                $str = $value;    // just return the value
            }
        } else {    // all meta tags
            $pattern = '/ |,/i';    // ' ' or ','
            $array = preg_split($pattern, $value, -1, PREG_SPLIT_NO_EMPTY);    // split it in an array, so we have the count of words           
            $str .= '

' . $key . ' (' . count($array) . ' words | ' . strlen($value) . ' chars)' . $value . '

'; // format data with count of words and chars } } return $str; } ?>
How you can use get_meta_data
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/

$content = get_meta_data("http://4evertutorials.blogspot.com/"); 

echo "
";
print_r($content);
echo "
"; ?>

Monday, August 4, 2014

get title, meta tags info in php

This php script grab title tag and description, keywords meta of specified url with simple php curl function. And show all information in title tag , meta description and meta keywords tags.

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

function file_get_contents_curl($url)
{
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

    $data = curl_exec($ch);
    curl_close($ch);

    return $data;
}

$html = file_get_contents_curl("http://4evertutorials.blogspot.com/");

$doc = new DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');
$title = $nodes->item(0)->nodeValue;
$metas = $doc->getElementsByTagName('meta');

for ($i = 0; $i < $metas->length; $i++)
{
    $meta = $metas->item($i);
    if($meta->getAttribute('name') == 'description')
        $description = $meta->getAttribute('content');
    if($meta->getAttribute('name') == 'keywords')
        $keywords = $meta->getAttribute('content');
}

echo "Title: $title". '

';
echo "Description: $description". '

';
echo "Keywords: $keywords";





?>

Friday, August 1, 2014

manage email accounts using cPanel API in php

In this blog post we learn how php class can create and manage email accounts using the cPanel API. It can send HTTP requests to the cPanel API of a hosting account to perform several types of operations to manage email accounts.

Currently this class has following functions:
- check if a given email account exists
- create a new email account
- get the list of created email accounts
- change the password of an email account
- delete an email account.

For use this class first create a file name "class.email.php" without double quote. And copy following code , paste and save.

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


class cPanelEmailManager {
    private $cpanelHost;
    private $cpanelPort;
    private $username;
    private $password;
    private $logcurl;
    private $cookiefile;
    private $curlfile;
    private $emailArray;
    private $cpsess;

    /**
     * Constructor
     * @param string $user cPanel username
     * @param string $pass cPanel password
     * @param string $host cPanel domain
     * @param int $port cPanel domain
    */
    public function __construct($user,$pass,$host,$port=2083){
        $this->cpanelHost = $host;
        $this->cpanelPort = $port;
        $this->username = $user;
        $this->password = $pass;
        $this->logcurl = false;
        $this->cookiefile = "cpmm/cpmm_cookie_".rand(99999, 9999999).".txt";
        $this->LogIn();
    }

    /**
     * Checks if an email address exists
     * @param string $Needle Email address to check
     * @param bool $FullEmailOnly If false, will return true with or without the domain attached
     * @return bool
    */
    public function emailExists($Needle, $FullEmailOnly = false){
        $Haystack = empty($this->emailArray) ? $this->getEmails() : $this->emailArray;
        foreach($Haystack as $H){
            if($FullEmailOnly === true && $H['email'] == $Needle){
                return true;
            }else if($FullEmailOnly !== true && ($H['user'] == $Needle || $H['email'] == $Needle)){
                return true;
            }
        }
        return false;
    }

    /**
     * Creates a new email address
     * @param string $email Complete mail address to create, ie. myemail@mydomain.com
     * @param string $password Password for new email
     * @param string $quota Disk Space Quota, 0 for unlimited
     * @return bool
    */
    public function createEmail($email,$password,$quota = 0){
        if($this->emailExists($email,true)){
            return "Email address ".$email." already exist";
        }
        $e = explode("@",$email);
        $params = 'user='.$this->username.'&pass='.$this->password;;
        $url = "https://".$this->cpanelHost.":".$this->cpanelPort.$this->cpsess."/json-api/cpanel".
        "?cpanel_jsonapi_version=2".
        "&cpanel_jsonapi_func=addpop".
        "&cpanel_jsonapi_module=Email&".
        "email=".$e[0]."&".
        "domain=".$e[1]."&".
        "password=".urlencode($password)."&".
        "quota=".$quota;
        $answer = json_decode($this->Request($url,$params), true);
        $this->getEmails(true);
        return ($answer["cpanelresult"]["data"][0]['result'] === 1) ? true : false;
    }

    /**
     * Deletes an email address
     * @param string $email Complete mail address to delete, ie. myemail@mydomain.com
     * @return bool
    */
    public function deleteEmail($email){
        if(!$this->emailExists($email,true)){
            return "Email address ".$email." does not exist";
        }
        $e = explode("@",$email);
        $params = 'user='.$this->username.'&pass='.$this->password;;
        $url = "https://".$this->cpanelHost.":".$this->cpanelPort.$this->cpsess."/json-api/cpanel".
        "?cpanel_jsonapi_version=2".
        "&cpanel_jsonapi_func=delpop".
        "&cpanel_jsonapi_module=Email&".
        "email=".$e[0]."&".
        "domain=".$e[1];
        $answer = json_decode($this->Request($url,$params), true);
        $this->getEmails(true);
        return ($answer["cpanelresult"]["data"][0]['result'] === 1) ? true : false;
    }

    /**
     * Changes a password
     * @param string $email Complete email of account, ie. myemail@mydomain.com
     * @param string $newPW New password
     * @return bool
    */
    public function changePW($email, $newPW){
        if(!$this->emailExists($email,true)){
            return "Email address ".$email." does not exist";
        }
        $e = explode("@",$email);
        $params = 'user='.$this->username.'&pass='.$this->password;;
        $url = "https://".$this->cpanelHost.":".$this->cpanelPort.$this->cpsess."/json-api/cpanel".
        "?cpanel_jsonapi_version=2".
        "&cpanel_jsonapi_func=passwdpop".
        "&cpanel_jsonapi_module=Email&".
        "email=".$e[0]."&".
        "domain=".$e[1]."&".
        "password=".urlencode($newPW);
        $answer = json_decode($this->Request($url,$params), true);
        $this->getEmails(true);
        return ($answer["cpanelresult"]["data"][0]['result'] === 1) ? true : false;
    }

    /**
     * Lists all email accounts and their properties
     * @param int $pageSize Number of results per page
     * @param int $currentPage Page number to start from
     * @param bool $paginate Return in pages
     * @param bool $sort Sort the results
     * @param bstring $sortby Column to sort by, ie. "email", "_diskused", "mtime", or "domain"
     * @return array
    */
    public function listEmails($pageSize = 10, $currentPage = 1, $paginate = true, $sort = true, $sortby = "user"){
        $params = 'user='.$this->username.'&pass='.$this->password;;
        $url = "https://".$this->cpanelHost.":".$this->cpanelPort.$this->cpsess."/json-api/cpanel".
        "?cpanel_jsonapi_version=2".
        "&cpanel_jsonapi_func=listpopswithdisk".
        "&cpanel_jsonapi_module=Email".
        "&api2_paginate=".($paginate === false ? 0 : 1).
        "&api2_paginate_size=".$pageSize.
        "&api2_paginate_start=".$currentPage.
        "&api2_sort=".($sort === false ? 0 : 1).
        "&api2_sort_column=".$sortby.
        "&api2_sort_method=alphabet".
        "&api2_sort_reverse=0";
        $answer = $this->Request($url,$params);
        $emails = json_decode($answer, true);
        $this->emailArray = $emails["cpanelresult"]["data"];
        return $this->emailArray;
    }

    /**
     * Turns cURL logging on
     * @param int $curlfile Path to curl log file
     * @return array
    */
    public function logCurl($curlfile = "cpmm/cpmm_curl_log.txt"){
        if(!file_exists($curlfile)){
            try{
                fopen($curlfile, "w");
            }catch(Exception $ex){
                if(!file_exists($curlfile)){
                    return $ex.'Cookie file missing.'; exit;
                }
                return true;
            }
        }else if(!is_writable($curlfile)){
            return 'Cookie file not writable.'; exit;
        }
        $this->logcurl = true;
        return true;
    }
    
    /**
     * Returns a complete list of emails and their properties
     * @access private
    */
    private function getEmails($refresh = false){
        if(!empty($this->emailArray) && !$refresh){
            return $this->emailArray;
        }
        $params = 'user='.$this->username.'&pass='.$this->password;;
        $url = "https://".$this->cpanelHost.":".$this->cpanelPort.$this->cpsess."/json-api/cpanel".
        "?cpanel_jsonapi_version=2".
        "&cpanel_jsonapi_func=listpopswithdisk".
        "&cpanel_jsonapi_module=Email";
        $answer = $this->Request($url,$params);
        $emails = json_decode($answer, true);
        $this->emailArray = $emails["cpanelresult"]["data"];
        return $this->emailArray;
    }

    /**
     * Starts a session on the cPanel server
     * @access private
    */
    private function LogIn(){
        $url = 'https://'.$this->cpanelHost.":".$this->cpanelPort."/login/?login_only=1";
        $url .= "&user=".$this->username."&pass=".urlencode($this->password);
        $answer = $this->Request($url);
        $answer = json_decode($answer, true);
        if(isset($answer['status']) && $answer['status'] == 1){
            $this->cpsess = $answer['security_token'];
            $this->homepage = 'https://'.$this->cpanelHost.":".$this->cpanelPort.$answer['redirect'];
        }
    }

    /**
     * Makes an HTTP request
     * @access private
    */
    private function Request($url,$params=array()){
        if($this->logcurl){
            $curl_log = fopen($this->curlfile, 'a+');
        }
        if(!file_exists($this->cookiefile)){
            try{
                fopen($this->cookiefile, "w");
            }catch(Exception $ex){
                if(!file_exists($this->cookiefile)){
                    echo $ex.'Cookie file missing.'; exit;
                }
            }
        }else if(!is_writable($this->cookiefile)){
            echo 'Cookie file not writable.'; exit;
        }
        $ch = curl_init();
        $curlOpts = array(
            CURLOPT_URL             => $url,
            CURLOPT_USERAGENT       => 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0',
            CURLOPT_SSL_VERIFYPEER  => false,
            CURLOPT_RETURNTRANSFER  => true,
            CURLOPT_COOKIEJAR       => realpath($this->cookiefile),
            CURLOPT_COOKIEFILE      => realpath($this->cookiefile),
            CURLOPT_FOLLOWLOCATION  => true,
            CURLOPT_HTTPHEADER      => array(
                "Host: ".$this->cpanelHost,
                "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
                "Accept-Language: en-US,en;q=0.5",
                "Accept-Encoding: gzip, deflate",
                "Connection: keep-alive",
                "Content-Type: application/x-www-form-urlencoded")
        );
        if(!empty($params)){
            $curlOpts[CURLOPT_POST] = true;
            $curlOpts[CURLOPT_POSTFIELDS] = $params;
        }
        if($this->logcurl){
            $curlOpts[CURLOPT_STDERR] = $curl_log;
            $curlOpts[CURLOPT_FAILONERROR] = false;
            $curlOpts[CURLOPT_VERBOSE] = true;
        }
        curl_setopt_array($ch,$curlOpts);
        $answer = curl_exec($ch);
        if (curl_error($ch)) {
            echo curl_error($ch); exit;
        }
        curl_close($ch);
        if($this->logcurl){
            fclose($curl_log);
        }
        return (@gzdecode($answer)) ? gzdecode($answer) : $answer;
    }
}



?>

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


	// include the library
	require("class.email.php");

	// cPanel domain or IP
	$host = "mywebsite.com";

	// cPanel Username
	$user = "cPanel_Username";

	// cPanel Password
	$pass = "cPanel_Password";

	if($host == "mywebsite.com"){
	    echo "Put your cPanel credentials in and remove line ".__LINE__." from the example script before running."; exit;
	}

	// initialize the class
	$cpmm = new cPanelEmailManager($user, $pass, $host);

	// Create a new email address
	$email = "newemail@mywebsite.com";
	$password = "mybadpassword";
	$result = $cpmm->createEmail($email,$password);
	echo "Email ($email) ".($result ? "successfully" : "not")." created.
"; // Check if an email exists $email = "newemail@mywebsite.com"; $result = $cpmm->emailExists($email); echo "Email ($email) ".($result ? "does" : "does not")." exist.
"; // Change an email password $email = "newemail@mywebsite.com"; $newPassword = "mybetterpassword"; $result = $cpmm->changePW($email,$newPassword); echo ($result ? "Changed" : "Could not change")." password for email $email.
"; // Delete an email account $email = "newemail@mywebsite.com"; $result = $cpmm->deleteEmail($email); echo ($result ? "Deleted" : "Could not delete")." email account $email.
"; // List email accounts $pageSize = 15; $pageNo = 1; $result = $cpmm->listEmails($pageSize, $pageNo); var_dump($result); ?>




 

© 2014 4everTutorials. All rights resevered.

Back To Top