GitHub Issue: Login Does Not Redirect After Successful Authentication in Local Deployment
Title
Login succeeds via AJAX but does not redirect to dashboard due to base URL mismatch and lost session state
Summary
When the project is deployed locally at http://127.0.0.1:3000/, the login form may either:
- show
An error occoured!, or
- stop showing the popup but still remain on the login page after valid credentials are submitted.
This issue was caused by two separate problems in the login flow:
- the frontend AJAX request used a hard-coded
base_url that did not match the active local deployment URL
- after successful authentication, the next request could lose the expected login session and regenerate an empty session
Environment
- Project:
School-Student-Management-System
- Stack:
PHP + CodeIgniter 3 + MySQL + jQuery
- Local URL used during debugging:
http://127.0.0.1:3000/
Symptoms
Case 1: AJAX error popup
The login page showed:
This came from the frontend error callback in:
Case 2: No popup, but no redirect
After fixing the request URL, the login API could return success, but the browser still stayed on the login page instead of reaching the correct dashboard.
Expected Behavior
- valid credentials should redirect the user to the correct role dashboard
- invalid credentials should stay on the login page and show the normal invalid-login UI
Actual Behavior
- login AJAX initially requested the wrong endpoint because
base_url did not match the running host
- after that was fixed, authentication could succeed but the next page request still behaved as unauthenticated in the local environment
Root Cause
1. Hard-coded base URL mismatch
The project configuration used:
$config['base_url'] = 'http://localhost/School-Student-Management-System/';
While the app was actually being accessed at:
Because the login page generates:
var baseurl = '<?php echo base_url(); ?>';
the frontend AJAX request was sent to the wrong URL.
2. Session state was not preserved reliably after AJAX login
Even when the login endpoint returned login_status=success, the following request could regenerate a new empty ci_session, which caused the application to render the login page again instead of the authenticated dashboard.
Changes Made
Change 1: Fix local deployment base URL
Updated:
application/config/config.php
From:
$config['base_url'] = 'http://localhost/School-Student-Management-System/';
To:
$config['base_url'] = 'http://127.0.0.1:3000/';
This ensures the login page submits AJAX requests to the actual running host.
Change 2: Stabilize post-login authentication state
Implemented a fallback authentication restore mechanism for local session instability:
- added
application/core/MY_Controller.php
- updated
Login.php to extend MY_Controller
- updated protected controllers to extend
MY_Controller
Admin.php
Teacher.php
Student.php
Parents.php
Modal.php
- issued a signed auth cookie after successful login
- restored role session from that signed cookie before access checks
- cleared the auth cookie on logout
- changed successful login responses to return a role-specific dashboard URL directly
Files Changed
application/config/config.php
application/core/MY_Controller.php
application/controllers/Login.php
application/controllers/Admin.php
application/controllers/Teacher.php
application/controllers/Student.php
application/controllers/Parents.php
application/controllers/Modal.php
Verification
Verified that:
- the login API returns
success for valid credentials
- the response now includes a role-specific redirect URL
- authenticated requests can reach the correct dashboard page
Example verified redirect response:
{
"submitted_data": {
"password": "123",
"email": "riham@gmail.com"
},
"login_status": "success",
"redirect_url": "http://127.0.0.1:3000/index.php?student/dashboard"
}
Notes
- The signed auth cookie fallback was introduced as a practical source-level fix for the local debugging environment where the expected session continuity was not stable across requests.
- If the deployment environment is later normalized, the session implementation can be simplified again.
Suggested Labels
bug
login
session
codeigniter
local-dev
GitHub Issue: Login Does Not Redirect After Successful Authentication in Local Deployment
Title
Login succeeds via AJAX but does not redirect to dashboard due to base URL mismatch and lost session state
Summary
When the project is deployed locally at
http://127.0.0.1:3000/, the login form may either:An error occoured!, orThis issue was caused by two separate problems in the login flow:
base_urlthat did not match the active local deployment URLEnvironment
School-Student-Management-SystemPHP + CodeIgniter 3 + MySQL + jQueryhttp://127.0.0.1:3000/Symptoms
Case 1: AJAX error popup
The login page showed:
This came from the frontend error callback in:
assets/js/neon-login.jsCase 2: No popup, but no redirect
After fixing the request URL, the login API could return
success, but the browser still stayed on the login page instead of reaching the correct dashboard.Expected Behavior
Actual Behavior
base_urldid not match the running hostRoot Cause
1. Hard-coded base URL mismatch
The project configuration used:
While the app was actually being accessed at:
Because the login page generates:
var baseurl = '<?php echo base_url(); ?>';the frontend AJAX request was sent to the wrong URL.
2. Session state was not preserved reliably after AJAX login
Even when the login endpoint returned
login_status=success, the following request could regenerate a new emptyci_session, which caused the application to render the login page again instead of the authenticated dashboard.Changes Made
Change 1: Fix local deployment base URL
Updated:
application/config/config.phpFrom:
To:
This ensures the login page submits AJAX requests to the actual running host.
Change 2: Stabilize post-login authentication state
Implemented a fallback authentication restore mechanism for local session instability:
application/core/MY_Controller.phpLogin.phpto extendMY_ControllerMY_ControllerAdmin.phpTeacher.phpStudent.phpParents.phpModal.phpFiles Changed
application/config/config.phpapplication/core/MY_Controller.phpapplication/controllers/Login.phpapplication/controllers/Admin.phpapplication/controllers/Teacher.phpapplication/controllers/Student.phpapplication/controllers/Parents.phpapplication/controllers/Modal.phpVerification
Verified that:
successfor valid credentialsExample verified redirect response:
{ "submitted_data": { "password": "123", "email": "riham@gmail.com" }, "login_status": "success", "redirect_url": "http://127.0.0.1:3000/index.php?student/dashboard" }Notes
Suggested Labels
bugloginsessioncodeigniterlocal-dev