Friday, April 15, 2016

PHP 7 with Microsoft SQL Server Driver Released



Microsoft announced on 12th April 2016 early technical preview of the Microsoft Driver 4.0.3 for PHP for SQL Server, using this driver you can connect your PHP application with Microsoft SQL Server currently this server is available only for PHP 7. This Driver enable you to access SQL Server, Azure SQL Database and Azure SQL DW from your PHP 7 apps.

Download Driver


Future Plans

Microsoft plan on a Linux port, expand SQL 16 Feature Support (example: Always Encrypted), build verification/fundamental tests, bug fixes.
This early technical preview provide some limited support on this github page here

We hope this add-on will help you in your future development.

Source: https://blogs.msdn.microsoft.com/sqlphp/2016/04/12/early-technical-preview-of-microsoft-drivers-4-0-3-for-php-for-sql-server-released/

Friday, March 4, 2016

Different between CodeIgniter and Laravel frameworks

Different between CodeIgniter and Laravel frameworks


Here, let us make a brief analysis and know the differences between Laravel and CodeIgniter.

Laravel pros and cons

It is common knowledge that, for web application development, Laravel offers expressive, elegant syntax. Such has been its design. The laravel developer will enjoy the development process. Routing, authentication, sessions are some tasks, which are commonly performed, and are made easier, thanks to Laravel.

Importantly, this framework is designed for the PHP's latest version. Therefore, unit testing support and authentication, which are the base development components, are inbuilt. It is commendable that Laravel framework folds with the blade template engine in a smooth manner.

One area where Laravel outdoes CodeIgniter is it has got exceptions. These, with exceedingly detailed stacktrace aren't available for developers who use CodeIgniter..

Use of libraries and models is easier as Laravel has object-oriented libraries. These libraries are supported with autocomplete feature.

Laravel has its own command-line interface. Called as Artisan, it enables developers to perform abundant tasks. So what tasks? Tasks like migrating databases and seeding databases. Also performed is clearing the cache, etc.

Object-Relational Mapping or ORM in Laravel is simple, eloquent and fast. That said, developers will find it very easy to organize the application's database.

Laravel is best suited for building RESTful APIs. Apart from that, Laravel handles event queuing.

However, Routing in Laravel may be odd at times. Owing to the recent entry of Laravel, it may be a bit tougher if not altogether, to get to find answers. Notwithstanding this fact, the numerous forums and IRC are very much active in helping people find answers.


CodeIgniter pros and cons

It is simple, and also quick to set up CodeIgniter. Just download the preferred version from CodeIgniter homepage. Otherwise, from GitHub. Thereafter, unzip the contents.

Nothing can beat CodeIgniter in terms of documentation, which is clear and very well structured. It is such that all the particular concepts of CodeIgniter which are commonly used are explained clearly, that too, with examples.

CodeIgniter is stable. The popular framework has the advantage of having been tested by the developers in large number. Having said that, the chances of bugs or any other problems going unnoticed is minimal.

The templating engine, which is inbuilt in CodeIgniter, is easy to use and is based on mustache-like templating language. Learning this language is simple even for new developers.

No matter whether you know anything about MVC architecture or not; it is very easy to use CodeIgniter.

CodeIgniter offers output caching. Web pages can be cached so that the loading time can be reduced. Besides, efficiency and performance can be enhanced.

Developers using CodeIgniter can easily seek support. Because this framework has a very big community which uses the framework for smaller projects and also very large projects.

It may be an overstatement to call CodeIgniter obsolete. However, it is to be noted that the framework has been released at the time of PHP 4. Many new features were added later to PHP. Hence, the need for extending code files arises to make this framework work.

Another drawback of CodeIgniter is that it does not offer default modular separation.

Both frameworks, which are unique and similar in many ways have their own set of advantages and disadvantages. However, it is the requirements of the developers that decide which is to be preferred. All that said, if you are a developer working on modern apps, it is suggested you go for Laravel. Every Laravel developer company attributes their ease of web development to this framework.

Wednesday, June 10, 2015

Get webpage loading time using PHP



Execution of server side scripting need to optimize in order to get the Optimized page loading time. In this case most of the Server Side Response typically not more than 2 to 30 seconds. In this case we need to find the Exact page loading time in PHP using the following Script.
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/

function page_loading_time()
{
    list ($msec, $sec) = explode(' ', microtime());
    $microtime = (float)$msec + (float)$sec;
    return $microtime;
}

$start=page_loading_time();

usleep(100000);  // Delaying page output 0.1 second for testing purpose.

echo "
";
$end = page_loading_time();
// Print results.
echo 'Page Loading Time: ' . round($end - $start, 2) . ' seconds';   


?>

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.

Thursday, May 7, 2015

Text rasterization service script using php


This is an example of using Gd / FreeType to generate image text labels with TTF font. Provided script could be used as "text rasterization service" to generate arbitrarily text-images for a web site. MD5-based authorization is used to avoid image generation by unauthorized users.

Compatible with:

PHP 5 or higher
PHP 4.1 or higher
Gd 2.x, FreeType support in PHP


Our "text rasterization service" does the following:

Receives text generation parameters(text and font-size) and md5 sign of secret key + parameters.

Checks(by md5 sign) if rasterized text image exists in cache directory. If so, sends it to web browser and quits.

Checks md5 authorization: computes md5 of secret key + parameters. If computed md5-sign equals to provided md5-sign, then request is valid. Otherwise — somebody else is trying to use our "text rasterization service".

Generates text image with imagettftext. Image size exactly matches text size (using imagettfbbox)

Sends generated image to browser

So, it is possible to automatically generate a lot of image text labels for a whole web site. Caching technique will decrease server load: images would be generated only once.



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

// Checking for gd and Freetype support 
if (!function_exists('gd_info'))
  die('No gd support in PHP.');

$gd = gd_info();
if ($gd["FreeType Support"] == false)
  die('No FreeType support in gd');

// If you're sure about gd & freetype support
// -- comment out this block 



// directory for caching generated images 
// should be writable 
$cache_dir = '/home/path/to/cache'; // DO NOT FORGET TO CHANGE


// testing cache dir 
// remove these lines if you're sure 
// that your cache dir is really writable to PHP scripts
$tf = $cache_dir.'/'.md5(rand()).".test";
$f = @fopen($tf, "w");
if ($f == false)
    die("Fatal error! {$cache_dir} is not writable. Set 'chmod 777 {$cache_dir}' 
           or something like this");
fclose($f);
unlink($tf);
// testing cache dir END 




// full path to preferred TTF font 
// you could change this to be HTTP parameter 
$font = '/home/path/to/font/FuturaBook.ttf'; // DO NOT FORGET TO CHANGE


// md5 secret 
$md5_secret_key = 'changeme'; // DO NOT FORGET TO CHANGE


// md5 sign of parameters
$auth_sign = isset($_GET['a'])?$_GET['a']:'';

// checking for cached file:
$cache_file = $cache_dir.'/'.$auth_sign.'.png';

if (file_exists($cache_file))
{
  // if cached file exists
  // output it and quit
  header("Content-type: image/png");
  readfile($cache_file);
  exit();
}

// no cached file exists 


// input parameters: text and size 
$text = isset($_GET['text'])?$_GET['text']:'default';

$font_size = isset($_GET['size'])?intval($_GET['size']):30;
if ($font_size == 0) $font_size = 30;
// 


// basic sign checking: 
$computed_sign = md5($md5_secret_key.$text.$font_size);
// computing md5 sum of concatenation 
// of secret key and parameters

// hmac-based alrorithm would fit this case more 
// but for real-world purpose md5 of concatenation
// is enought 

if ($computed_sign != $auth_sign)
  die('Auth failed'); // auth error, provided sign is invalid 


// getting bounding box 
$bbox = imagettfbbox($font_size, 0, $font, $text);
// imagettfbbox returns very strange results 
// so transforming them to plain width and height 

$size_w = abs($bbox[2] - $bbox[0]);
// width: right corner X - left corner X

$size_h = abs($bbox[7] - $bbox[1]);
// height: top Y - bottom Y

// This is a lower-left corner 
// but imagettfbbox() sets (0,0) point
// inside bounding box
// so we shifting lower-left corner
$x = -abs($bbox[0]); 
$y = $size_h - abs($bbox[1]);

$im = imagecreatetruecolor($size_w, $size_h);
// creating image

$back = imagecolorallocate($im, 255, 255, 255); // background color
$fore = imagecolorallocate($im, 0, 0, 0); // foreground color

imagefilledrectangle($im, 0, 0, $size_w - 1, $size_h - 1, $back);
// filling with background color

imagettftext($im, $font_size, 0, $x, $y, $fore, $font, $text);
// rendering text

imagepng($im, $cache_file); // outputing PNG image to file cache 

imagedestroy($im); // destroy image 


// sending data from cache file 
header("Content-type: image/png");
readfile($cache_file);


?>


To generate image 'Hello World', 90 pixels size you should call this script as (assuming you've saved it as font.php):


<img src="./font.php?text=Hello+World&size=90&a=4c9a240e98490275d845c96fdb8e5a19">


Note parameter 'a=4c9a240e98490275d845c96fdb8e5a19'. '4c9a240e98490275d845c96fdb8e5a19' is a result of md5('changemeHello World90'): concatenation of secret key, text and font size.

You could use some helper function to set script arguments, like 'image_params':
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/

$md5_secret_key = 'changeme';

// returns parameters and md5 sign for 
// text generating service
function img_params($text, $size) 
{
  global $md5_secret_key;
  $p = '?text='.urlencode($text).'&size='.$size.'&a=';
  return $p.md5($md5_secret_key.$text.$size);
}

?>

<html><head><title>Test</title></head>
<body>

<center>
<img src="./font.php<?php echo img_params('Hello World', 90);?>">
</center>

</body>
</html>
 

Thursday, April 2, 2015

Htaccess code syntax to prevent your wordpress website from attackers

Htaccess code syntax to prevent your wordpress website from attackers 
Hypertext access (.htaccess) file is the common name of a directory-level configuration file which allows decentralised management of web server configuration. A .htaccess file is always added to the root directory, it can override many other configuration settings which includes server’s global configuration, content type and character set.



 A .htaccess file can be used for lots of hacks that will secure and improve functionality for WordPress blogs and websites. Following are lists of main htaccess code snippets which will improve and prevent WordPress sites from hackers. Some will allow to block specific IP addresses to visit the site, redirect visitors to maintenance page when particular site is redesigned or modified, prevent IP addresses to login into the wordpress admin section etc.


Blacklist undesired users and bots ip address
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/


order allow,deny
allow from all
deny from 132.151.389
deny from 91.131.784
deny from 773.966.769
deny from 178.406.880



?>


Redirect visitors to a maintenance page
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/

RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.php$
RewriteCond %{REMOTE_ADDR} !^123.123.123.123
RewriteRule $ /maintenance.php [R=302,L]


?>


Redirect www to non www or vice versa
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.yourblogpath.com [NC]
RewriteRule ^(.*)$ http://yourblogpath.com/$1 [L,R=301]
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^yourblogpath.com [NC]
RewriteRule ^(.*)$ http://www.yourblogpath.com/$1 [L,R=301]


?>


Force Caching with htaccess
The following htaccess code won’t help the initial pageload, but it will significantly help subsequent pageloads by sending 304 statuses when requested elements haven’t been modified.
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/

FileETag MTime Size
ExpiresActive on
ExpiresDefault "access plus x seconds"


?>


Allow only your IP adress on the wp-admin directory
Replace your IP with allow from xx.xx.xx.xx which will only allow your IP to access wp-admin directory.
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/

AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName "Wordpress Admin Access Control"
AuthType Basic

order deny,allow
deny from all
allow from xx.xx.xx.xx



?>


The easiest way to ban a WordPress spammer
To block certain IP address from accessing your blog enter the following code into .htaccess file and replace example IP address with the one you want to ban.
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/


## USER IP BANNING

order allow,deny
deny from 670.45.145.125
allow from all


?>


Deny access to your wp-config.php file
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/

# protect wpconfig.php

order allow,deny
deny from all



?>



Limit the File upload size to 10MB
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/

# limit file uploads to 10mb
LimitRequestBody 10240000


?>


Password protected directories
A simple way to password protect blog directories
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/

AuthType Basic
AuthName "restricted area"
AuthUserFile /usr/local/var/www/html/.htpasses
require valid-user


?>


Quickly secure plugin files
WordPress plugin files might have a loop hole and may allow hackers to get into your website. To prevent others to have direct access to plugin files use following code.
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/


  order allow,deny
  allow from all



?>

Saturday, March 21, 2015

Popular Security Libraries for PHP Developers

Today, PHP is one of the most popular web programming language for creating dynamic websites. There is bunches of data on the web that PHP developers make utilization of. On the other hand, few of them are obsolete and can manage anybody to compose "awful code.

In this post, we have introduced to popular PHP security libraries that will help them to create security interfaces for web applications. If you have any suggestion regarding PHP Security Libraries please write in comment box. Thanks

Popular Security Libraries for PHP Developers


HTML Purifier

HTML Purifier is a standards-compliant HTML filter library written in PHP. HTML Purifier will not only remove all malicious code (better known as XSS) with a thoroughly audited, secure yet permissive whitelist, it will also make sure your documents are standards compliant, something only achievable with a comprehensive knowledge of W3C’s specifications.

URLcrypt

URLcrypt makes it easy to securely transmit short pieces of binary data in a URL. Use it to securely store things like user IDs, download expiration dates, and more. URLcrypt uses 256-bit AES symmetric encryption to securely encrypt data, and encodes and decodes Base 32 strings that can be used directly in URLs.

PHP Intrusion Detection System

PHPIDS (PHP-Intrusion Detection System) is a simple to use, well structured, fast and state-of-the-art security layer for your PHP based web application. The IDS neither strips, sanitizes nor filters any malicious input, it simply recognizes when an attacker tries to break your site and reacts in exactly the way you want it to. Based on a set of approved and heavily tested filter rules any attack is given a numerical impact rating which makes it easy to decide what kind of action should follow the hacking attempt. This could range from simple logging to sending out an emergency mail to the development team, displaying a warning message for the attacker or even ending the user’s session.

TCrypto

TCrypto is a simple and flexible PHP 5.3+ in-memory key-value storage library. By default, a cookie will be used as a storage backend. TCrypto has been designed from the ground up with security in mind. Safe algorithms and modes. Automatic and safe initialization vector creation. Encryption and authentication key creation (Keytool) using strong randomness. Key rotation (versioned keys). TCrypto can be used as a scalable “session handler”. Especially scalable, if cookies are used as a storage backend. This is a bit like Ruby on Rails sessions.

PHP Password Lib

PHP-PasswordLib aims to be an all-inclusive cryptographic library for all cryptographic needs. It is meant to be easy to install and use, yet extensible and powerful enough for even the most experienced developer.

PHPSecLib

phpseclib is designed to be ultra-compatible. It works on PHP4+ (PHP4, assuming the use ofPHP_Compat) and doesn’t require any extensions. For purposes of speed, mcrypt is used if it’s available as is gmp or bcmath (in that order), but they are not required.

Hybrid Auth

HybridAuth is an open source PHP library for authenticating through multiple social services and ID providers. The services supported include OpenID,Facebook, LinkedIn, Google,Twitter, Windows Live, Foursquare, Vimeo, Yahoo, PayPal and more. It can be integrated easily into existing websites by inserting a file and few lines to the sign-in/up pages.

Security Check – Sensiolabs

This tool is almost essential to both beginners and experienced PHP coders. The way it works is quite simple, you upload your .lockfile and it does the rest for you. If you look at the stats, the numbers of vulnerabilities found is quite staggering, don’t be surprised if your own projects might output some nasty stuff that you have missed.

SecurityMultiTool

A multitool library offering access to recommended security related libraries, standardised implementations of security defences, and secure implementations of commonly performed tasks. The purpose of the library is to serve as both a useful set of utilities and to act as a set of reference implementations which can be learned from. It may be used by applications regardless of whether they are web application framework based or not. The use of a web application framework does not guarantee your security.

What is contrast in the middle of MYISAM and InnoDB?


What is contrast in the middle of MYISAM and InnoDB?

In this post, I am explaining to each one of PHP developer to understand the difference between MYISAM and INNODB

MYISAM
1. MYISAM supports Table-level Locking
2. MyISAM designed for need of speed
3. MyISAM does not support foreign keys hence we call MySQL with MYISAM is DBMS
4. MyISAM stores its tables, data and indexes in diskspace using separate three different files. (tablename.FRM, tablename.MYD, tablename.MYI)
5. MYISAM not supports transaction. You cannot commit and rollback with MYISAM. Once you issue a command it’s done.

INNODB
1. InnoDB supports Row-level Locking
2. InnoDB designed for maximum performance when processing high volume of data
3. InnoDB support foreign keys hence we call MySQL with InnoDB is RDBMS
4. InnoDB stores its tables and indexes in a tablespace
5. InnoDB supports transaction. You can commit and rollback with InnoDB

Friday, December 19, 2014

Parse Website with PHP

Parse Website with PHP

Parsing website pages is always a challenge for PHP Developers. Parsing is using for retrieving images, scraping websites, crawling, error detection websites, and many other useful purposes. But PHP Simple HTML DOM Parser is a awesome or can say dream library for developer that work with both PHP and the DOM element using PHP.


You can get the Simple HTML DOM Parser from here and save file to any directory of your choice. First in a basic example we’ll include the class, and get all hyperlinks on the http://4evertutorials.blogspot.com .

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

// Include the parser library
include('simple_html_dom.php');

// Retrieve the DOM from a given URL
$html_dom = file_get_html('http://4evertutorials.blogspot.com/');

// scan for all hyperlinks and print
foreach ($html_dom->find('a') as $element) {
       print $element->href;
}

?>
Below are few basic uses of PHP Simple HTML DOM Parser.
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/

// Include the parser library
include('simple_html_dom.php');

// Retrieve the DOM from a given URL
$html = file_get_html('http://4evertutorials.blogspot.com/');

// Find all anchor tags and print their HREFs
foreach($html->find('a') as $e) 
    echo $e->href;

// Retrieve all images and print their SRCs
foreach($html->find('img') as $e)
    echo $e->src;

// Find all images, print their text with the "<>" included
foreach($html->find('img') as $e)
    echo $e->outertext;

// Find all SPAN tags that have a class of "SpanClass"
foreach($html->find('span.SpanClass') as $e)
    echo $e->outertext;

// Find all TD tags with "align=center"
foreach($html->find('td[align=center]') as $e)
    echo $e->innertext;

// Extract all text from a given cell
echo $html->find('td[align="center"]', 1)->plaintext;

// Find the DIV tag with an id of "DivId"
foreach($html->find('div#DivId') as $e)
    echo $e->innertext;


?>

Thursday, October 16, 2014

Install CodeIgniter Framework


In this post we will cover how to install codeigniter framework and we will view the most common steps to install codeigniter framework. CodeIgniter is one of the most popular PHP frameworks around. It uses the Model-View-Controller Architectural design pattern and it’s considered by lots of PHP developers as one of the best framework solution for small to medium projects.

How to Install

The installation itself is such a simple process. First of all, you need to download the CodeIgniter zipped file, upload it to your server and extract it into your home directory. You can download it from https://ellislab.com/codeigniter/user-guide/installation/downloads.html.

Configuring CodeIgniter

Congratulations, now you have CodeIgniter installed on your server. Now it’s time for configuration. Open the application/config/config.php file with your preferred editor and set your base URL. If you intend to use encryption or sessions, set your encryption key. For the database configuration, open the application/config/database.php file with your preferred editor and set your database host, name, user, password and other values that you think it will help you connect to your database. You will find array variables with comments to know the role of each value.

Configuration files

By editing the two previously mentioned files, you are ready to start coding your first web application but CodeIgniter contains more files that enable more configuration and customization abilities. The configuration files can be found in the application/config/ directory. The following is a quick description of what you can do by editing some of the most commonly used configuration files:

autoload.php : specifies which systems (Packages, Libraries, Helper files, Custom config files, Language files and Models) should be loaded by default.

config.php : contains all website configuration.

constants.php : contains defined constants which are used when checking and setting modes when working with the file system.

database.php : contains the settings needed to access your database.

email.php : This file is not created by default. But you can create it and set the default values for the email class. Like: mailtype, charset, newline, protocol, smtp_host, etc.

hooks.php : lets you define “hooks” to extend CI without editing the core files.

mime.php : contains an array of mime types. It is used by the upload class to help identify allowed file type.

routes.php : lets you re-map URI requests to specific controller functions.

smileys.php
: contains an array of smileys for use with the emoticon helper.

upload.php : This file is not created by default. But you can create it and set the default values for the upload class. Like: upload_path, allowed_types, max_size, max_width, max_height, etc.

user_agents.php : contains four arrays of user agent data. It is used by the User Agent Class to help identify browser, platform, robot, and mobile device data. The array keys are used to identify the device and the array values are used to set the actual name of the item.

Monday, October 6, 2014

php To PDF

php To PDF is an API based solution. We are a web service providing you the easiest way to generate PDF files from PHP Code.

Our server does the heavy lifting and generates the PDFs for you. The generated PDF files will be returned and stored on your server in the specified directory with your specified file name, or you can set them to be created and displayed or downloaded by a user on the fly.

You do not need any special packages or permissions. It works on any server running PHP!

We have simplified our API so that you just need to download the phpToPDF.php file from your account and include it in your code. It's that simple.

Get started :: PHP to PDF generation steps
Sign up to access our API   
2  FREE!
Download and include phpToPDF.php

Sample Code

Use the phptopdf() function for creating a PDF using a URL



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


    require('phpToPDF.php');

    //Set Your Options -- see documentation for all options
    $pdf_options = array(
          "source_type" => 'url',
          "source" => 'http://google.com',
          "action" => 'save');

    //Code to generate PDF file from options above
    phptopdf($pdf_options);
 

?>



Alternatively, you can use the phptopdf() function to pass a varible that holds html code for your PDF.

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

    require('phpToPDF.php');

    //Your HTML in a variable
    $my_html="

PDF from HTML using phpToPDF

"; //Set Your Options -- we are saving the PDF as 'my_filename.pdf' to a 'my_pdfs' folder $pdf_options = array( "source_type" => 'html', "source" => $my_html, "action" => 'save', "save_directory" => 'my_pdfs', "file_name" => 'my_filename.pdf'); //Code to generate PDF file from options above phptopdf($pdf_options); ?>


[ More Examples ]

Thursday, September 4, 2014

New features in PHP 5.6

The PHP development team announced new release of PHP 5.6. The new release brings new features and lots of improvements, development team say, also as some backward incompatible changes.

Following are the most important changes in PHP 5.6 release:




Constant scalar expressions
It is now possible to provide a scalar expression involving numeric and string literals and/or constants in contexts where PHP previously expected a static value, such as constant and property declarations and default function arguments.
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/

const ONE = 1;
const TWO = ONE * 2;

class C {
    const THREE = TWO + 1;
    const ONE_THIRD = ONE / self::THREE;
    const SENTENCE = 'The value of THREE is '.self::THREE;

    public function f($a = ONE + self::THREE) {
        return $a;
    }
}

echo (new C)->f()."\n";
echo C::SENTENCE;

//The above example will output:
/*
4
The value of THREE is 3
*/

?>
Improved syntax for variadic functions
Variadic functions can be declared through a new ... operator:

<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/
 
function f($req, $opt = null, ...$params) {
    // $params is an array containing the remaining arguments.
    printf('$req: %d; $opt: %d; number of params: %d'."\n",
           $req, $opt, count($params));
}

f(1);
f(1, 2);
f(1, 2, 3);
f(1, 2, 3, 4);
f(1, 2, 3, 4, 5);

// The above example will output:
/*
$req: 1; $opt: 0; number of params: 0
$req: 1; $opt: 2; number of params: 0
$req: 1; $opt: 2; number of params: 1
$req: 1; $opt: 2; number of params: 2
$req: 1; $opt: 2; number of params: 3
*/

?>
Argument unpacking via ... operator
Arrays and Traversable objects can be unpacked into argument lists when calling functions by using the ... operator. This is also known as the splat operator in other languages, including Ruby.

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

function add($a, $b, $c) {
    return $a + $b + $c;
}

$operators = [2, 3];
echo add(1, ...$operators);

// The above example will output:
/*
6
*/
?>

Exponentiation via ** operator
A right associative ** operator has been added to support exponentiation, along with a **= shorthand assignment operator.

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

printf("2 ** 3 ==      %d\n", 2 ** 3);
printf("2 ** 3 ** 2 == %d\n", 2 ** 3 ** 2);

$a = 2;
$a **= 3;
printf("a ==           %d\n", $a);

// The above example will output:
/*
2 ** 3 ==      8
2 ** 3 ** 2 == 512
a ==           8
*/

?>


use function and use const
The use operator has been extended to support importing functions and constants in addition to classes. This is achieved via the use function and use const constructs, respectively.


<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/ 
 
namespace Name\Space {
    const FOO = 42;
    function f() { echo __FUNCTION__."\n"; }
}

namespace {
    use const Name\Space\FOO;
    use function Name\Space\f;

    echo FOO."\n";
    f();
}

// The above example will output:
/*
42
Name\Space\f
*/


?>

Now UTF-8 is Default character encoding
default_charset is now used as the default character set for the htmlentities(), html_entity_decode() and htmlspecialchars() functions. Note that if the (now deprecated) iconv and mbstring encoding settings are set, they will take precedence over default_charset for iconv and mbstring functions, respectively.

Large file uploads 
Files larger than 2 gigabytes in size are now accepted.

GMP supports operator overloading
GMP objects now support operator overloading and casting to scalar types. This allows for more expressive code using GMP:
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/ 
 
$a = gmp_init(42);
$b = gmp_init(17);

// Pre-5.6 code:
var_dump(gmp_add($a, $b));
var_dump(gmp_add($a, 17));
var_dump(gmp_add(42, $b));

// New code:
var_dump($a + $b);
var_dump($a + 17);
var_dump(42 + $b);

?>

Full list of all changes in PHP 5.6 can be additionally found in the here.

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

                )

        )

)


?>

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');



?>

 

© 2014 4everTutorials. All rights resevered.

Back To Top