How to set the timezone in CodeIgniter

date_default_timezone_set() function is used to sets the default timezone used by all date or time functions in core PHP, CodeIgniter etc.

date_default_timezone_set();
date_default_timezone_set('Asia/Kolkata');

# Option-1: In case of CodeIgniter, we can set the default timezone in the application/config.php file

In case of CodeIgniter, we can set the default timezone in the
application/config.php file

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

date_default_timezone_set('Asia/Kolkata');

# Option-2:
Place the code in the main index.php of Codeigniter folder

date_default_timezone_set('Asia/Kolkata');

How to Get the Header Data CakePHP or PHP?

I Personally Tried a lot for getting the posted header data in cakephp.

The Header data required to check the posted token. Token validation , to check the posted request is valid or not.

Finally I found the Solution.
PHP It self has a function named, getallheaders()

Syntax: getallheaders ( void ) : array
Description: Fetches all HTTP headers from the current request.

Return Values::
An associative array of all the HTTP headers in the current request, or FALSE on failure.

Example #1 getallheaders() example

$headers = getallheaders();
foreach( $headers as $name => $value) {
     echo "$name: $value\n";
}

Example: Received Data:

Array
(
     [Host] => 127.0.0.1
     [Connection] => keep-alive
     [Content-Length] => 264
     [auth_token] => 20dea7c13dada345dgf80815d3546393a98
     [device_id] => adada23456
     [Cache-Control] => no-cache
     [Origin] => chrome-extension://fhbjgjbdggehcddcbncdddomop
     [User-Agent] => Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36
     [Postman-Token] => 2d5b612b-e2db-1202-50f1-925cb2f8fa05
     [Content-Type] => multipart/form-data; boundary=----WebKitFormBoundarySssj4jB1U7xNxnHy
     [Accept] => */*
     [Accept-Encoding] => gzip, deflate, br
     [Accept-Language] => en-GB,en-US;q=0.9,en;q=0.8
     [Cookie] => PHP=lm68fsfbhedsvbb6b96
)

Source: https://www.php.net/manual/en/function.getallheaders.php

How to Create Unique Number in PHP?

Option-1:

$mt_rand = mt_rand(1000000000, 9999999999); 
echo $mt_rand;

Option-2:

$unique_id = uniqid();
echo $unique_id;
 uniqid( prefix, more_entropy ) 

prefix:
Can be useful, for instance, if you generate identifiers simultaneously on several hosts that might happen to generate the identifier at the same microsecond.

With an empty prefix, the returned string will be 13 characters long. If more_entropy is TRUE, it will be 23 characters.

more_entropy:
If set to TRUE, uniqid() will add additional entropy (using the combined linear congruential generator) at the end of the return value, which increases the likelihood that the result will be unique.

source: https://www.php.net/manual/en/function.uniqid.php

Option-3:

$mt_rand = mt_rand(1000000000, 9999999999);
$timestamp = time();
$temp = $mt_rand + $timestamp;
$temp2= substr($tmp, 0,10);

echo $temp2;

How to Increment value clicking plus minus icon in Jquery?

Html Code:

<div class="csdisplayorder" >
    <span class='csminus glyphicon glyphicon-minus'></span>
    <input class="cscurrent" type="text" disabled value="1" data-rid="1" data-pid="2">
    <span class='csplus glyphicon glyphicon-plus'></span>
</div>

Script:

<script type="text/javascript">
$(document).ready(function(){
    $('.csdisplayorder .csplus').live('click', function(){
        var dis = $(this);
        var input_obj = dis.parent().find('.cscurrent');
        var input_val = parseInt(input_obj.val());
        if(input_val == undefined){
            input_obj.val(0);
        }else{
            var new_val =  parseInt(input_val)+1;
            input_obj.val(new_val);
            $(this).fncsUpdateRoomDisplayOrder(dis, new_val);
        }
    });

    $('.csdisplayorder .csminus').live('click', function(){
        var dis = $(this);
        var input_obj = dis.parent().find('.cscurrent');
        var input_val = parseInt(input_obj.val());
        if(input_val == undefined){
            input_obj.val(0);
        }else{
            if(parseInt(input_val) >0){
                var new_val =  parseInt(input_val)-1;
                input_obj.val(new_val);

                $(this).fncsUpdateRoomDisplayOrder(dis, new_val);
            }
        }
    });

    $.fn.fncsUpdateRoomDisplayOrder = function(dis,nval) { 
        var input_obj = dis.parent().find('.cscurrent');
        var rid = input_obj.data('rid');
        var pid = input_obj.data('pid');

        var datastring = {'nval':nval,'rid':rid,'pid':pid}
        var xhrequest = false;
        xhrequest = $.ajax({
            url: base_url+'update',
            type:'post',
            dataType: 'json',
            data:datastring,
            async:false, 
            beforeSend: function (){
                if (xhrequest) {
                    xhrequest.ajaxStop();
                    console.log("xhrequest");
                }
            },
            success: function(data){
                xhrequest = false;
                console.log(data);
            }
        });
    }
});
</script>

CSS:

<style type="text/css">
.csdisplayorder{width: 62px;text-align: center;}
.csdisplayorder .cscurrent{width: 25px;float: none;background-color: white;border: none;text-align: center;}
.csdisplayorder .csplus,.csminus{padding: 3px;background-color: grey;color: white;border-radius: 10px;}
.csdisplayorder .csminus{float: left; }
.csdisplayorder .csplus{float: right;}
.csdisplayorder .cscurrent_txt{width:25px;float:none;vertical-align:-webkit-baseline-middle;vertical-align: sub;}
.csdisplayorder input[type=number].cscurrent::-webkit-inner-spin-button, 
.csdisplayorder input[type=number].cscurrent::-webkit-outer-spin-button { 
  -webkit-appearance: none; margin: 0; }
</style>