I am using html, javascript, and php. My login.htm page lets the user enter the login details. It then submits through the javascript to a php page checkinglogin.php which checks the login details against a database. The call from the javascript to php is asynchronous. So it waits for the response from php page.
The checkinglogin.php page checks against the database and then responds to the javascript
- If successful it starts the session and sets a session variable with the user id.
- Sends back a message to the javascript either Error or "Success"
The javascript inturn (depending on the response from php) displays the error OR redirects the user to a new page listing.htm
All is working fine.
Now I want to be able to display the listing.htm page only if the session has been started and the user has successfully logged in. Currently, listing.htm is accessible if dont log in and just type in the url in the browser.
My idea is that somehow if we can check on listing.htm page that if the session variable is not set then redirect the user to the login.htm page.
Not sure what can be done here to achieve the required functionality.