Unique Session variable per Script (not login)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
IGGt
Forum Contributor
Posts: 173
Joined: Thu Nov 26, 2009 9:22 am

Unique Session variable per Script (not login)

Post by IGGt »

Hi guys,

I have a couple of pages that I'm running, one accesses local servers, one accesses remote servers, but other than that they are the same. The page refreshes automatically every 60 seconds, and loads the new information.

I recently started using $session variables to pass data across each time the page refreshes, and also to count how many times thepage has refreshed. But, when run side by side they both use the same session variable for the page counting (and maybe other info, I haven't checked that). So I might have page 1 which has refreshed 150 times, then I open page 2 for the first time, and it tells me it has refreshed 151 times.

Is there a way to set some kind of unique identifier on each page so the page count is correct?

I'm currently using:

Code: Select all

session_start();  
if(isset($_SESSION['views']))
    $_SESSION['views'] = $_SESSION['views']+ 1;
else
    $_SESSION['views'] = 1;
to count the page views.
IGGt
Forum Contributor
Posts: 173
Joined: Thu Nov 26, 2009 9:22 am

Re: Unique Session variable per Script (not login)

Post by IGGt »

Found it, and it was easier thanI thought.

session_name('site1');
session_start;
Post Reply