class Test extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->objOfJwt = new ImplementJwt();
header('Content-Type: application/json');
}
/////////// Generating Token and put user data into token ///////////
public function LoginToken()
{
$tokenData['uniqueId'] = '55555';
$tokenData['role'] = 'admin';
$tokenData['timeStamp'] = Date('Y-m-d h:i:s');
$jwtToken = $this->objOfJwt->GenerateToken($tokenData);
echo json_encode(array('Token'=>$jwtToken));
}
While making project in Codeigniter framework many developers face these problems:
php http_response_code not working
Http response code always returns 200
php http_response_code not working when hosting a linux server
404 page not found in not working
php 500 not working in codeigniter
header already sent error in php
warning cannot modify header information headers already sent by (output started xyz.php line no...
All these problems occur when you host your website at Linux server that you have developed in codeigniter framework. You have to modify index.php file which is in the root directory of Codeigniter framework. Step 1) Add ob_start(); function at the beginning of index.php after <?php This function will turn on the output buffering. so that http response code works correctly. Step 2) define('ENVIRONMENT','development'); The modified index.php file is as
How to validate json data or json nested array in codeigniter
For example we have two fields email and password to validate and sending request from postman as shown below: request method: post { "email":"sachinsharma.one@gmail.com", "password":"12345" } In controller public function login_post() { header('Content-type: application/json'); $request = json_decode(file_get_contents('php://input'),true); $this->form_validation->set_data($request); /// for setting data $this->form_validation->set_rules('email','Email', 'required|valid_email'); $this->form_validation->set_rules('password','PASSWORD', 'required|min_length[4]|max_length[20]'); if($this->form_validation->run()==false) { echo validation_errors(); } else { // your code.............. } } In this way you can validate json data or even big json data
Hi friends we are always ready to provide you job alerts of Govt as well as private. we provide you study material, question bank of computer and question papers of various competitive exams.
Questions asked in Htet computer science PGT Level-3
Q.1…………….. symbol is used to see every column of a table?