Thursday, 31 July 2014

Checking if Cookies are Enabled in Browser

The simplest way to check for cookies is via JavaScript. The following function will return a boolean value -> true if cookies are enabled:, otherwise will return false.
<script >
function are_cookies_enabled()
  {
 var cookieEnabled = (navigator.cookieEnabled) ? true : false;

 if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled)
 { 
  document.cookie="testcookie";
  cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
 }
 return (cookieEnabled);
  }

 var result= are_cookies_enabled();
 alert(result);
</script>

A snippet of code using the function above was executed when you loaded this page. resutl will display true or false

Monday, 28 July 2014

Delete image from folder in php

We are using image upload coding image moved on particular folder. after delete that database record data only deleted but image stay on same folder,Following line of code is used to Delet image from folder.
unlink('foldername/'.$imagename);
<?php
if(file_exists('imagesfolder/'.$image_name)){
  unlink('imagesfolder/'.$image_name);
}
?>

Thursday, 24 July 2014

Get all dates between two dates using php code.

In this Example giving two dates as "2014-07-24" and "2014-07-31" it return all days between these two dates.
<?php
function getAllDatesBetweenTwoDates($strDateFrom,$strDateTo)
{
    $aryRange=array();

    $iDateFrom=mktime(1,0,0,substr($strDateFrom,5,2),     substr($strDateFrom,8,2),substr($strDateFrom,0,4));
    $iDateTo=mktime(1,0,0,substr($strDateTo,5,2),     substr($strDateTo,8,2),substr($strDateTo,0,4));

    if ($iDateTo>=$iDateFrom)
    {
        array_push($aryRange,date('Y-m-d',$iDateFrom)); // first entry
        while ($iDateFrom<$iDateTo)
        {
            $iDateFrom+=86400; // add 24 hours
            array_push($aryRange,date('Y-m-d',$iDateFrom));
        }
    }
    return $aryRange;
}

$fromDate = '2014-07-24';
$toDate = '2014-07-31';

$dateArray = getAllDatesBetweenTwoDates($fromDate, $toDate);

    print_r($dateArray);

?>
Output will be :

Friday, 13 June 2014

Get Facebook Likes Count of a page using Graph API

This small code snippet given below uses FaceBook’s graph api and returns the likes count of the page. There is no need to have the FaceBook access token to call the api and get the result.
<?php
//The following code returns the Number of likes for any facebook page.
 
//Page Id of Knowledgecotner Replace it with your page.
$page_id = "556271807742934";
$likes = 0; //Initialize the count
 
//Construct a Facebook URL
$json_url ='https://graph.facebook.com/'.$page_id.'';
$json = file_get_contents($json_url);
$json_output = json_decode($json);
 
//Extract the likes count from the JSON object
if($json_output->likes){
    $likes = $json_output->likes;
}

//Printing the count
echo $likes.' Facebook Fans';
?>

Tuesday, 10 June 2014

How To Display Twitter Followers Count In PHP


Twitter is one of the most used social networking websites on the internet. Twitter API allows you to retrieve info for specific user. All you need to do is to enter the handler of the user. You can easily retrieve a specific Twitter user’s followers count with a small snippet:

Friday, 6 June 2014

Php : create pdf from html using mpdf


MPDF
Many php applications need to create pdf of documents like invoice , receipt and even id card etc. In this article we shall create a pdf invoice using the mpdf pdf creation library. Mpdf is made in php without any other external library. Mpdf parses css much better than any other free pdf libraries like tcpdf and creates pdf files which resemble the original html file to a large extent. Along with html to pdf, mpdf can also be used to create 1d barcodes of various formats.

Friday, 30 May 2014

Cron Job in ubuntu with php


Hi Friends Today iam working on cron job, it is Easy Process.....

If we put the file in cron, It will run automatically by setting the time limit. Using time limit we have run the file every min/hour/day/month etc.