Jump to content

Session variable not set on some occasions


otuatail

Recommended Posts

Hi. I am a bit confused over my logging system of a website. I have used it for years without a problem. I use a session variable to store the current page being accessed. This allows me to use a database to log a history.

$page = "Arts";
.
.
$_SESSION["current_page"] = $page;

I can use this to populate the database. If the session variable is blank then this obviously is the first attempt to access the website and is identified as a hit count. This works but some ip address’s don’t work.

Tue 15-Dec-2009 08:59:58 69.58. 178.28 RL-Home Hit

Tue 15-Dec-2009 09:00:03 69.58. 178.28 About Hit

Tue 15-Dec-2009 09:00:07 69.58. 178.28 Contacts Hit

Tue 15-Dec-2009 09:00:10 69.58. 178.28 HIV Hit

This is a brief log. As you see this agent is going through my web pages but the session variable is never set, making each access appear as a first time. I can have a hit count of 30 when it is the same agent accessing it.

 

The full information retrieved for this is

 

Tue 15-Dec-2009 08:59:58 69.58.

178.28

RL-Home

Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.3; ips-agent) Gecko/20090824 Fedora/1.0.7-1.1.fc4 Firefox/3.5.3

 

Link to comment
Share on other sites

I suggest you do a bit of research of how a Session works, it's a common misconception. Sessions (by default) require cookies. Yes, as you say the information is stored on the server, but how do you think the server associates different sessions with individual users? The way this works by default is a Session ID is sent to the client and stored in a Cookie, then each time a client makes a request this Session ID is sent to the server. The server will then use this ID to find that individual users Session Cookie (which is stored on the server). You can track Session ID's in other manners, such as persisting it via the URL (as I'm sure you will have seen on sites before), but that doesn't change the fact that by default, cookies are required to run Sessions.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.