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 redirect to https with www using .htaccess?

First check in your server

Redirect to https and www:

By using the .htaccess technique redirects to the https and www versions of your web pages to https://www.example.com. Add to site’s root .htaccess file:


RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)$  [NC]
RewriteRule (.*) https://www.%1/$1 [R=301,L]

Here, Checks if HTTPS is off, or if the request does not include www,
If either condition matches, the request follow the rule and it is redirected to the https://www.example.com

Redirect to https and non-www


RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule (.*) https://example.com/$1 [L,R=301]

How to Make a Query in CakePHP?

CakePHP

To Query from Table in CakePHP we can use the below code. We can also Query like ORDER_BY, Select Table FIELDS etc.

# Find Order from Order Table in CakePHP

$this->Order->find('all', array(
   'recursive' => -1,
   'conditions'=>array( 'Order.id'=>1 ),
   'fields' => array( 'Order.date', 'Order.id', 'Order.total'),
   'order' => array('Order.date' => 'DESC'),
));


# For Order By filter in Querry, we can use.

   'order' => array('Order.date' => 'DESC'),
or,
   'order' => array('Order.date DESC'),
or,
   'order' => 'Order.date ASC',

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