Set TimeOut in file_get_contents

            $ctx_opts = array('http' => array('timeout' => 10));
            $context = stream_context_create($ctx_opts);
            $response = file_get_contents($URL, false, $context);

            if ($response === false) {
                $error_message = error_get_last();
                echo  $error_message;
            }

WampServer Multiple PHP Versions

This  document is intended for use with:
WampServer version 2.5 : Apache : 2.4.9 MySQL : 5.6.17 PHP : 5.5.12
Sometimes, you need to run multiple PHP versions for some projects using wamp.  So this time I will show you how to configure wamp server 2.5  to run several php versions(one per time). Lets start:
1. Download phpxxxxxx.zip package for windows from  http://windows.php.net/downloads/releases/archives/.   i.e. php-7.0.0
2. Extract it on yourpath/wamp/bin/php/php5.x.xx folder (i.e wamp/bin/php/php7.0.0/)

Lets Start the configuration. Lets go in wamp/bin/php/php7.0.0/  (working directory for steps 3 to 5)

3. Copy and paste php.ini-development and rename it to php.ini and open it for editing.
a. Search the word “extension_dir” and add the follow line
extension_dir = “C:/path/to/your/wamp/bin/php/php7.0.0/ext/”
b. Then search “upload_tmp_dir and add
upload_tmp_dir = “C:/path/to/your/wamp/tmp
c. Search “http://php.net/session.save-path” and add the follow line below it
session.save_path = “C:/path/to/your/wamp/tmp
4.  Now copy the php.ini and paste it as “phpForApache.ini” in the same folder. So you will have php.ini and phpForApache.ini.
5. Create a new file called wampserver.conf and paste the following content.
<?php
 $phpConf['phpIniDir'] = '.';
 $phpConf['phpExeDir'] = '.';
 $phpConf['phpConfFile'] = 'php.ini';

 $phpConf['apache']['2.4']['LoadModuleName'] = 'php5_module';
 $phpConf['apache']['2.4']['LoadModuleFile'] = 'php5apache2_4.dll';
 $phpConf['apache']['2.4']['AddModule'] = '';

 $phpConf['apache']['2.4']['LoadModuleName'] = 'php7_module';
 $phpConf['apache']['2.4']['LoadModuleFile'] = 'php7apache2_4.dll';
 $phpConf['apache']['2.4']['AddModule'] = '';
?>
6. Now open C:/path/to/wamp/wampmanager.ini to tell wamp that we have another php version. Search the section [phpVersion] and add the line as follow :
Type: item; Caption: "7.0.0"; Action: multi; Actions:switchPhp7.0.0
Then search this line:
Parameters: "http://www.wampserver.com/addons_php.php";
And add the following lines below it:

[switchPhp7.0.0]
Action: resetservices
Action: readconfig;

Thats all. Close wampserver and open it again. you will see the new php version to be elegible.
Remember to change  C:/path/to/wamp to your wamp path.
PD: Please comment any mistake or issue.  I will try to improve this article later.  Hope, it can help someone.

List Directory in php

<?php

$dir    = '/tmp';
$files1 = scandir($dir);
$files2 = scandir($dir, 1);

print_r($files1);
print_r($files2);

?>

Lazy Load Images using javascript


/***--------------  JS File ------------------------***/

$(window).bind("load", function(){
 var timeout = setTimeout(function() {
  $('.lazyload1second').each(function(){      
   $(this).attr('src', $(this).attr('original_link')).fadeIn(700);
   $(this).removeAttr('original_link');   
  });
 }, 500);
});



/***--------------  Image Tag ------------------------***/


<img  width="100%" src="/images/right_banner_loader.jpg" original_link="/images/Mobikwik_homebanner.jpg" alt="Get 100 off on meru cabs" class="lazyload1second">

Done...

Install SSL Certificate On wamps server (localhost)

How to enable SSl on Wamp Server(apache2) - HTTPS Configuration

In this article, I will show how to Configure/Enable SSL in Wamp Server.I have installed wampserver with apache 2.2.12 and php 5.3.5. I have to configure the Open SSL server.
How to Setup HTTPS SSL on WAMP Server for apache 2.2

1. Install WAMPServer
2. Open Control Panel
3. Click System >> Select Advanced System Setting >> Select Environment Variables.
4.Create new system variable OPENSSL_CONF:
Value: C:\wamp\bin\apache\apache2.2.12\conf\openssl.cnf

5. Create a SSL Certificate and Key for the Web Server
Open command prompt and Run the following commands:

>cd wamp\bin\apache\apache2.2.12\bin
>openssl genrsa -des3 -out server.key 1024
>copy server.key server.key.org
>openssl rsa -in server.key.org -out server.key
>openssl req -new -x509 -nodes -sha1 -days 365 -key server.key -out server.crt -config C:\wamp\bin\apache\apache2.2.12\conf\openssl.cnf

Create a folder c:\wamp\OpenSSL with the following subfolders:
i. certificats
ii. private

Copy server.cert, server.csr, server.key files

from C:\wamp\bin\apache\Apache2.2.12\bin to C:\wamp\OpenSSL\certificats folder

Copy server.key.org file from

C:\wamp\bin\apache\Apache2.2.12\bin to C:\wamp\OpenSSL\private folder

6. Open Php.ini file

Remove comment of following line:
extension=php_openssl.dll

OR

Left click the wampserver icon >> PHP >> php extensions >> click php_openssl

7. Open Httpd.conf file (C:\wamp\bin\apache\Apache2.2.12\conf\)

Remove comment of following lines:

LoadModule ssl_module modules/mod_ssl.so
LoadModule setenvif_module modules/mod_setenvif.so
Include conf/extra/httpd_ssl.conf

8.Open httpd-ssl.conf file(C:\wamp\bin\apache\Apache2.2.12\conf\extra\)

Find and replace follwing lines:

SSLMutex default

DocumentRoot "C:/wamp/www"
ErrorLog "C:/wamp/logs/ssl_ErrorLog.txt"
TransferLog "C:/wamp/logs/ssl_TransferLog.txt"
SSLCertificateFile "C:/wamp/OpenSSL/certificats/server.crt"
SSLCertificateKeyFile "C:/wamp/OpenSSL/certificats/server.key"
CustomLog "C:/wamp/logs/ssl_request.txt" \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
Change Directory Tag:
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all

9.Verify SSL/HTTPS

•Run httpd –t and make sure the syntax is OK.

•Restart Apache.

10.Check whether the WAMP server is running or not

Right click the wampserver icon >> Rsstart All Services
•If icon is partially red, it means no service is currently running
•If icon is White, that means all services are running.

11.Open https://localhost
12.Done.

I hope this article will help you to enable SSL on the Apache server.

Ohh Missed below Conf..

Found a solution:

Here are the instructions how to get rid of the SSLSessionCache message in XAMPP

1) Open file \xampp\apache\conf\httpd.conf

2) Somewhere in the LoadModule area add the following line:

LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
3) Save the file

4) Now open file \xampp\apache\conf\extra\httpd-ssl.conf

5) at line 70 add the line

SSLSessionCache "shmcb:logs/ssl_scache(512000)"
6) Save the file

7) Restart Apache

curl in php (How to set the authorization header using curl)




$service_url = 'https://example.com/something/something.json';
$curl = curl_init($service_url);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "username:password"); //Your credentials goes here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

 //IMP if the url has https and you don't want to verify source certificate

$curl_response = curl_exec($curl);
$response = json_decode($curl_response);
curl_close($curl);

var_dump($response);

Log file snippets in php

        $log_string = 'done';
$file_name  = '/var/log/logfilename.log';
$handle = fopen ( $file_name, 'a+' );
if ($handle) {
fwrite ( $handle, date ( 'Y-m-d H:i:s' ) . '  ' . $log_string . "\n" );
fclose ( $handle );
        }

How to Create Helper In Code-igniter (CI)

=================
date_diff_helper.php
=================

<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/**
 * CodeIgniter and PHPMailer integration as default CI email function will not set tls value
 *
 * @package CodeIgniter
 * @subpackage        Helpers
 * @category        Helpers
 * @author Nilesh Y, Intelliswift
 */
// ------------------------------------------------------------------------

if (!function_exists('time_diff_check')) {

    function time_diff_check($last_time) {
        if (!empty($last_time)) {
            $curent_time = date('Y-m-d H:i:s');
            $start_date = new DateTime($curent_time);
            $end_date = new DateTime($last_time);
            $interval = $start_date->diff($end_date);
            $days = $interval->days;
            return $days;
        } else {
            return 0;
        }
    }

}


/* End of file zend_framework.php */
/* Location: ./application/helpers/zend_framework_helper.php */


To Call the function use.
$this->load->helper('diff_helper');

time_diff_check($last_time);




Linux: Find Out Directory Size Command

Linux: Find Out Directory Size Command

Iam a new Linux user. How do I find out size of a directory on Linux operating systems using command line options?

You need to use the du command:
[a] Find and estimate file space usage.
Tutorial details
DifficultyEasy (rss)
Root privilegesNo
Requirementsdu
Estimated completion timeLess than a one minute
[b] Summarize disk usage of each FILE/Directory/Folder.
[c] Shows the sizes of directories and files.

Syntax

The basic syntax is:
du
du dirName
du [options] dirName

Examples

Without any options, du command shows the names and used space for each directories including all sub-directories in the current directory:
du
Sample outputs:
Fig.01: du command in action
Fig.01: du command in action
To find information about /etc and /home/nixcraft directory, enter:
du /path/to/dir
du /etc
du /home/nixcraft
du /root /home/nixcraft
Pass the -h option to get output in human readable format i.e. show output in kilobytes (K), megabytes (M) and gigabytes (G):
du -h /etc
du -h /dir1/file2
du -h /root
du -h

Sample outputs:
8.0K ./.vim
24K ./scripts
48K ./.ssh
16K ./.keychain
2.2M ./.lftp
2.4M .
Pass the -s option to see the total disk space used by a directory:
du -sh
du -sh /etc/
du -sh /etc /home/ /securebackup/

Sample outputs:
4.1M /etc
152K /home/
902M /securebackup/
Pass the -c to see a grand total for all of the files, type:
du -csh /root/ /etc/ /home/
Sample outputs:
2.4M /root/
4.1M /etc/
152K /home/
6.6M total

How to convert an entire MySQL database characterset and collation to UTF-8

First First, backup!
First, you need to set the default char sets on the database. This does not convert existing tables, it only sets the default for newly created tables.
ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;
Then, you will need to convert the char set on all existing tables and their columns. This assumes that your current data is actually in the current char set. If your columns are set to one char set but your data is really stored in another then you will need to check the MySQL manual on how to handle this.
ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
Some Usefull snippets 
ALTER DATABASE databasename CHARACTER SET utf8 COLLATE utf8_unicode_ci;
ALTER TABLE tablename CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Foreach Loop in PHP

       $paramsValues = array();
foreach($params as $key => $value)
{
$paramsValues[$key] = $value;
}

Ajax Syntax in javascript/jquery

$("#getWSDLfunction").click(function() {

$.ajax({
                                url: base_url+'testetes',
type: 'POST',
async:false,
data:{
 user_email:user_email
                     },
dataType: 'json',
error: function(){
//alert('Error loading');
},
success: function(data){
if(data == "logged out"){
window.location = base_url;
}

   }
});


});