0

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

  1. If successful it starts the session and sets a session variable with the user id.
  2. 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.

Novice
  • 515
  • 7
  • 22
  • Check [How to redirect in php](http://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php) – Yin Gang May 16 '16 at 04:09
  • if(session_var){let in}else{dont} –  May 16 '16 at 04:24
  • @Dagon where do i put this code on listing.htm? – Novice May 16 '16 at 04:27
  • its pseudo code and at the top, listing.html will also have to parse php –  May 16 '16 at 04:28
  • Novice. I recommend that you stop using .htm as your file format and switch everything over to .php. If your server doesn't parse .htm files like php, you won't be able to ask the question, "is this user logged in or not". – Brogan May 16 '16 at 06:06

0 Answers0