Hi!

I am a kind of newbie in PHP programming, but I have found an interesting
problem and some php guys I know were unable to help me to solve it. So I am
coming here with my question...

I have written a little more advanced counter, which should be included in
other PHP scripts in website.
It uses cookies, which expire in one year. That helps me to determine which
users are coming back to the website. It also uses sessions (session
cookies) to detect how one user is moving in the website in one session.
Program uses three MySQL tables - table of cookies (cookie ID, number of
visits), table of sessions (session ID, cookie ID, IP, browser,...) and
table of visited subpages in the website (session ID, visited location).

The program flow is simple:
1. Check the cookies. If user do not have a cookie, send it to him. Else
find cookie ID in the database (first table) and increase the counter.
2. Check session ID. If session is not registered, register it and set
'number of session visits counter' to 1, AND save session ID (+ cookie ID,
IP,...) to the second MySQL table.
If session is already registered, just increase the session visits counter.
3. Save session ID and visited location (I use the $REQUEST_URI variable) to
the third MySQL table.

It seems OK, but see what happened.
I explicitely said that if ($sess_visits == 1), variable $sessid is saved to
the second table. That means that $sessid must be unique - it should appear
in a table just once.
But when I exported data from table, I found that some $sessid appeared
twice or three times!

What could be the problem???

See a little bit of my code:

  ini_set("session.cookie_lifetime", "0");

  // Initialize session
  session_start();

  // Register session and set number of session visits variable to 1
  if (!session_is_registered('sess_visits')) {
      session_register('sess_visits');
      $sess_visits = 1;
  }
  else {
    $sess_visits++;
  }

  if ($sess_visits == 1) {
...
    // Save session, IP, etc. into database
    $sql = "INSERT INTO wc_sessionident SET sessid = '$sessid', ...";
...
  }

bye, Matej


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to