I have been messing around with adding sessions and I got everything to work. I can have users login, and it keeps track of all of their info through session_start(). However there is one strange thing that is bothering me. If someone is logged into the page, then if they leave and come back it appears they are not logged in for the first loading of the page. However if I click any of the links (which are stored on the same server), sure enough all their user information comes back up. I've sifted through my code and checked and it just doesn't keep track of their session id for the first page load after leaving the website. But when the page is reloaded it has their session id again.

I don't know a lot about how it works so If anyone could point me in the right direction, or let me know if this is even possible to fix. I have been trying to avoid cookies, but could use one to hold session id if I really had no other choice.

(I tried page redirection to the same page, and it worked. But I know some browsers such as chrome don't allow users to go to websites that redirect to the same server.)

Use the following in all pages.....

  1. session_start() in the first line after <?php
  2. check if session exists using if condition as below:

              do all coding within this block;
              display login page;

The login page can be displayed as below: