Reputation: 51
Using codeigniter 3 I have modified the following. config
$config['base_url'] = 'http://demo.xyz.com/xyz/';
$config['log_threshold'] = 4 ;
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
routes
$route['default_controller'] = 'Admin';
controller
class Admin extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('admin_model');
$this->load->helper('url');
$this->load->library("session");
$this->load->helper('form');
$this->load->library('form_validation');
}
public function index()
{
if(!$this->session->userdata('Usr_Mobile_No'))
{
redirect('admin/login');
}
$this->load->view('admin/index');
}
public function check_login()
{
//$name = $this->input->post('name');
$user_type = $this->input->post('user_type');
$mobile = $this->input->post('mobile');
$password = $this->input->post('password');
$admin_panel = $this->input->post('admin_panel');
$new_data = array('Usr_Mobile_No' => $mobile);
$this->session->set_userdata($new_data);
$sql1 = $this->admin_model->check_admin_login($user_type, $mobile, $password);
$redirect = base_url('admin/index');
$data['redirect'] = $redirect;
echo json_encode($data);
}
public function login()
{
$this->load->view('admin/login');
}
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
In my view folder I have login.php which has the following code
<form action="<?php echo base_url('admin/check_login'); ?>" method="post" id="signin_form" autocomplete="off"></form>
Update : I missed to add this line of code. It was already added.
On submit of this form I get "404 file or directory not found". I think it is trying to find check_login which is just a function. I also have an index.php in the view folder. Update Server is running php 8.3.
How do I debug this? Please advice.
Upvotes: 1
Views: 51
Reputation: 51
This may not be the answer anyone is looking for but Just to make sure why the code is not working I would like to inform that running CI3 on PHP>=8 is near impossible. Atleast it Is for me. If you have CI3 project, either downgrade your php version to less than 7 or upgrade your project to CI4. Even still there are a lot of tweaks to be performed on your code for it to work with CI4. But its better than fixing CI3 on php>8.
If anybody can provide a better answer I am willing to withdraw this as the selected answer.
That's all.
Upvotes: 0
Reputation: 26
You are almost there. Just add a login method in Admin Class.
<?php
class Admin extends CI_Controller
{
public function __construct()
{
parent::__construct();
//$this->load->model('admin_model');
$this->load->helper('url');
$this->load->library("session");
$this->load->helper('form');
$this->load->library('form_validation');
}
public function index()
{
if(!$this->session->userdata('Usr_Mobile_No'))
{
redirect('admin/login');
}
$this->load->view('admin/index');
}
public function login()
{
$this->load->view('login');
}
....
Upvotes: 0