Follow Me:
Showing posts with label Php. Show all posts
Showing posts with label Php. Show all posts

Friday, 28 October 2016

PHP sessions default timeout

We are settind the Session Time out in Php as mentioned as below:

session.gc_maxlifetime = 1440
(1440 seconds = 24 minutes)

Friday, 7 August 2015

Differences between InnoDB and MyISAM 

   In MySQL, major difference of InnoDB and  MyISAM are given below. MyIsam is supporting the table level locking in database. But InnoDB is supporting the row level locking in the database. MyIsam is supporting the FULL TEXT SEARCH functionality and InnoDB also supporting the FULL TEXT SEARCH after MySQL Version of 5.6.4.


 MyISAM Engine : 

1. It supporting Table-level Locking
2. It supports FULLTEXT SEARCH functionality
3. It is designed for need of speed
4. It is not supporting foreign key constraints
5. It is storing the data as its tables, data and indexes in diskspace using separate three different files formats. (table.FRM, table.MYD, table.MYI)
6. It is not supporting transactions [ We can't COMMIT and ROLLBACK the comments ]
7. It recovering data by using Requires full repair/rebuild of indexes/tables
8. It is storing the data as no ordering format

INNODB Engine : 

1. It is supporting Row-level Locking
2. After MySQL Version 5.6.4 ,Supporting FULL TEXT SEARCH functionality
3. It is designed for maximum performance when processing high volume of data
4. It is supporting foreign key constraints
5. It is supporting transactions [ We can COMMIT and ROLLBACK the comments ]
6. It stores data as tables and indexes in a tablespace
7. It is Auto recovery from crash via replay of logs
8. It is stored the data row as primary key order

Tuesday, 21 July 2015

CwebP Unsupported Color Conversion Request:

    When i am creating WebP images, that time triggering the error as "cwebp unsupported color conversion request, Error Could not be process file".


    $imageName  = "ilikekaraikudi.jpg";
    $webpimgName  = "ilikekaraikudi.webp";
   cwebp -q 0 ".$imageName." -o ".$webpimgName.
   Unsupported color conversion request
   Error! Could not process file ilikekaraikudi.jpg
   Error! Cannot read input picture 



    we can try converting to RBG color-space via ImageMagick (convert) or any other image-editor tool.

    exec("convert -colorspace RGB ".$imageName." ".$webpimgName . " ");

Related Posts:

   1. how to create webp image in php
   2. fedex shipping integration
   3. 413 “Request Entity Too Large” error with uploading a file

   4. How to blink text in html for various browsers
   5. Difference between cookies and sessions in php


Thursday, 16 July 2015


    WebP is an image file type that was created in 2010 and is created by Google. This image format provides lossless and lossy compression to images on the server. Big social media websites are using WebP image process are Google, Facebook and EBay.
  WebP images natively supporting to the following browsers are Chrome, Opera, Opera Mini, Android Browser and Chrome for Android browsers only. It is not supported any other browsers like Firefox, IE and Safari,etc.


    WebP lossless image files are 26% smaller than PNGs.
    WebP lossy images files are 25-34% smaller than JPEG images at equivalent SSIM index.
    WebP supports lossless transparency (also known as alpha channel) with just 22% more bytes.

WebP images creating process in php:

you can use following php commands,to get the webp images

$imgName     =   "codingslovers.jpg";
$webPName   =   "codingslovers.webp";


 cwebp [quality qualitypercentage] [source image] -o [destination]

exec("cwebp -q 0 ".$imgName." -o ".$webPName." ");

Another Method:

exec("convert -colorspace RGB ".$imgName." ".$webPName . " ");

Exec : executes the given command in php

Advantages of WebP:

Smaller file size
Different compression algorithm
Smoother color gradations
Alpha channel mask

Disadvantages of WebP:

Weak browser support
Artifacting has plastic appearance
Poor exporting interface

Browserwise WebP Performance:

Monday, 6 July 2015

Abstract class in PHP:

  •     Abstract Class  contains only declare the method's signature, they can't define the implementation.
    •     Abstraction class are defined using the keyword abstract .
    •     Abstract Class is not possible to implement multiple inheritance.
    •     Latest version of PHP 5 has introduces abstract classes and methods.
    •     Classes defined as abstract , we are unable to create the object ( may not instantiated ).

    •     we can extend the Abstract class, by using extends operator.
    •     we can inherit only one abstract class at one time extending.
    •     Any class that contains one abstract method must also be declare as abstract.
    •     All methods marked as abstract in the parent's class, declaration must be defined by the   child.
    •     Additionally, these methods must be defined with the same (or a less restricted) visibility           (Public,Protected & private).
    •     Type hint & number of parameter must be match between parent & child class.

      Related Posts:

    Wednesday, 13 May 2015

    What is JSON?

    JavaScript Object Notation (JSON) is a lightweight data-interchange format inspired by the object literals of JavaScript. 

    JSON values can consist of:

    •   objects (collections of name-value pairs)
    •   arrays (ordered lists of values)
    •   strings (in double quotes)
    •   numbers
    •   true, false, or null

    JSON is language independent.

    JSON with PHP?

       After PHP Version 5.2.0, JSON extension is decodes and encodes functionalities as default.

    • Json_encode     - returns the JSON representation of values
    • Json_decode     - Decodes the JSON String
    • Json_last_error - Returns the last error occured.

    JSON Syntax and Rules?

       JSON syntax is derived from JavaScript object notation syntax:

    • Data is in name/value pairs
    • Data is separated by commas
    • Curly braces hold objects
    • Square brackets hold arrays

    JSON Example

        This example is simple phone number validation and once phone number has validated , it will be sent this php page, there we are using the json format related encode data.

    Html Page:
    <title>JSON Example in Php</title>
    <script src="js/jquery-1.11.0.min.js"></script>
    <h1>Json Basic Example</h1>
    <form name="phone-form" method="post" onsubmit="return validation();">
     <input type="text" name="phone" id="phone" value="" >
     <input type="submit" value="submit" >
    <div id="outputDisplay"></div>

    Javascript Function

    function validation(value){ 
     //Phone Number Validations
     var phone   = $('#phone').val();
     var specialDigitPattern  = /[~`!@#\$%\^&\*()\-_\+=|\\{}\[\]:;"'<>,\?\/\.0123456789]/;
     //var mailvalidateregex  = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;  email validation
     if(phone == ""){
      alert("Please enter the phone ");
      return false;
     }else if(isNaN(phone)){
      alert('Please Enter Valid Phone Number');
      return false;
     var postdata  = 'phone='+phone;
     var url   = 'testphone.php?phone='+phone;
      type  : "POST",
      url   : url, 
      data  : postdata,
      dataType : "json",
      success  : phonestatus_check,
     return false;
    function phonestatus_check(response){
     if(response.status == 1){
      return false;

    Php Page:

      $phonenumber = $_POST['phone'];
      $responsearray = array();$responsestatus = '1';
      if($responsestatus == 1){
          $responsearray = array('status' => 1,'message'=> 'Thanks for submitting the Phone Number');
       $responsearray = array('status' => 0,'message'=> 'failure');
      echo json_encode($responsearray);
      /* $json = json_encode($responsearray);
       exit("{$_GET['jsoncallback']}($json)"); */

    Friday, 1 May 2015

    Nginx: 413 Request Entity Too Large Error and Solution

      My application is running nginx as a frond end to php based Apache server. My applicatio lets user upload images upto 2MB in size. When users trying to upload 1.5MB+ size image file using nginx reverse proxy, they are getting the following error on screen:

        Nginx 413 Request Entity Too Large

    You need to configure both nginx and php to allow upload size.

    Nginx configuration:
    The client_max_body_size directive assigns the maximum accepted body size of client 
     request, indicated by the line Content-Length in the header of request.
    If size is greater the given one, then the client gets the error "Request Entity Too Large" 
    (413). To fix this issue edit your nginx.conf.
    Open the Terminal or login to the remote server using ssh client. 
    Type the following command to edit your nginx.conf using a text editor such as vi or joe:
    # vi /etc/nginx/nginx.conf
    # vi /usr/local/nginx/conf/nginx.conf
    Add the following line to http or server or location context to increase 
     the size limit 
     in nginx.conf, enter:
    # set client body size to 2M #
    client_max_body_size 2M;
    Save and close the file. Reload the nginx webserver, enter:
    # /usr/local/nginx/sbin/nginx -s reload
    # /sbin/nginx -s reload
    OR use the following on RHEL/CentOS/Debian/Ubuntu Linux:
    # service nginx reload 

    PHP configuration (optional):
    Your php installation also put limits on upload file size. Edit php.ini and set the following directives ;This sets the maximum amount of memory in bytes that a script is allowed
    to allocate memory_limit = 32M ;The maximum size of an uploaded file. upload_max_filesize = 2M ;Sets max size of post data allowed.This setting also affects file upload.
    To upload large files, this value must be larger than upload_max_filesize post_max_size = 3M Save and close the file. Make sure you reload/restart back-end apache or
    nginx web server as per your setup

    Wednesday, 1 April 2015

    Cookies are stored in browser as a text file format.It is stored limit amount of data.It is only allowing 4kb[4096bytes].It is not holding the multiple variable in cookies.

    we can accessing the cookies values in easily.So it is less secure.The setcookie() function must appear BEFORE the <html> tag.

    Sessions are stored in server side.It is stored unlimit amount of data.It is holding the multiple variable in sessions. we cannot accessing the cookies values in easily.So it is more secure.



    Cookies are stored in browser as
    text file format.

    Sessions are stored in server side.

    It is stored limit amount of data.
    It is only allowing 4kb[4096bytes]

    It is stored unlimit amount of data.

    It is not holding the multiple variable
     in cookies.

    It is holding the multiple variable
     in sessions.

    we can accessing the cookies values
    in easily.
    So it is less secure.
     The setcookie() function must
     appear BEFORE the <html> tag

    we cannot accessing the cookies
    values in easily.
    So it is more secure.

    Destroy Cookies:

     1. if we Closing the browsers at the time
     cookies values destoryed.
     2. setting the cookie time to expire the cookie.

    Destroy Sessions :

     1. using unset() session,we will
    destroyed the sessions.
     2. using session_destory(), we we will
    destroyed the sessions.


      setcookie(name, value, expire, 
    path,domain, secure, httponly);

      $cookie_uame = "codingslover";

      $cookie_uvalue= "website";

      //set cookies for 1 hour time
    $cookie_uvalue3600, "/");

      //expire cookies


    //session variable
    $_SESSION['testvaraible'] = 'Codings';
    //destroyed the entire sessions
    session_destroy(); //Destroyed the session 
    variable "testvaraible".

    Wednesday, 25 February 2015

    Expire the session after some peiod of time by using in php.

    Basically, two methods are available to destory the sessions.

       1. session_destroy()
       2. unset($_SESSION['testvaraible'])
       3. setting the time out for this session


         if we will call the session_destroy(), it will destroy all the SESSION variable.It is no need any other parameters.


    2. unset($_SESSION['testvaraible'])

           When we will call the unset() ,it will destroyed the particular variable.
     // Destroyed the session variable "testvaraible".

    3. setting the time out for this session

    if isset($_SESSION['LAST_MINITUte_ACTIVITY']) && 
    (time() - $_SESSION['LAST_MINITUte_ACTIVITY'] > 1800)) { // last request was more than 30 minutes ago session_unset(); // unset $_SESSION variable for the run-time session_destroy(); // destroy session data in storage } // update last activity time stamp $_SESSION['LAST_MINITUte_ACTIVITY'] = time(); /* You can also use an additional time stamp to regenerate the session ID periodically,to avoid attacks on sessions like session fixation: */ if (!isset($_SESSION['CREATED'])) { $_SESSION['CREATED'] = time(); } else if (time() - $_SESSION['CREATED'] > 1800) { // session started more than 30 minutes ago // change session ID for the current session // an invalidate old session ID session_regenerate_id(true); $_SESSION['CREATED'] = time(); // update creation time }


       By using php ini_set session.gc_maxlifetime also we will expire the session.

     ini_set session.gc_maxlifetime


    Saturday, 10 January 2015

    How to resolved when Logged out sessions get restored by back button?

    When we log out the sessions , We clear the cookies in browser. But when we press the back button after logging out the session gets restored. 

     header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
     header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

    Monday, 3 November 2014

    JSON (Javascript Object Notation) is a convenient way to transport data between applications, especially when the destination is a Javascript application.

    Example :
    Here is a minimal example that uses JSON as the transport for the server response. The client makes an ajax request with the JQuery shorthand function $.getJSON. The server generates a hash, formats it as JSON and returns this to the client. The client formats this and puts it in a page element.

    get '/json' do
     content_type :json
     content = { :response  => 'Sent via JSON',
                :timestamp =>,
                :random    => rand(10000) }
    var url = host_prefix + '/json';
    $.getJSON(url, function(json){
      $("#json-response").html(JSON.stringify(json, null, 2));
       "response": "Sent via JSON",
       "timestamp": "2014-06-18 09:49:01 +0000",
       "random": 6074

    JSONP (JSON with Padding)

    JSONP is a simple way to overcome browser restrictions when sending JSON responses from different domains from the client. The only change on the Client side with JSONP is to add a callback parameter to the URL.

    get '/jsonp' do
     callback = params['callback']
     content_type :js
     content = { :response  => 'Sent via JSONP',
                :timestamp =>,
                :random    => rand(10000) }
    var url = host_prefix + '/jsonp?callback=?';
    $.getJSON(url, function(jsonp){
      $("#jsonp-response").html(JSON.stringify(jsonp, null, 2));
      "response": "Sent via JSONP",
      "timestamp": "2014-06-18 09:50:15 +0000",
      "random": 364