----- Original Message ----- From: "Chris Shiflett" <[EMAIL PROTECTED]> To: "Fireborn Silvaranth" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Tuesday, February 11, 2003 1:04 PM Subject: Re: [PHP] newbie-php user tracker prob
Pretty new to PHP but I've always wanted to make a user tracking system. I'm trying to grab a number (sessionNum) out of a text file and increment it whenever someone leaves and comes back to the site.. the problem is the text file appears to be cached somewhere, the first time someone comes back the value is incremented and appended but if they leave again and then come back the file's contents appear to be unchanged. Opening the file up after the first time reveals that it has been appended but after subsequent visits it is not (but yet it still goes through the function). I tried just appending the info on with 'a' but since it didnt work I have it rewriting the whole file.... still doesnt work however... thanks if you can give any help. an example of the file's contents: 1-12:17:2:Tuesday:February:11:2003--page1,page2,page3, (sessionNum-date-referer-pagelist) the function I'm using : function incSession($trackFile, $pagename){ if (file_exists($trackFile)){ //read the file $fileLine = file_get_contents($trackFile); print "alert('File contents before write : $fileLine');"; //split the tracker file's contents into major sections Session-Date-Referer-Pages $headerArray = explode("-", $fileLine); //get correct entry for last session number in the tracker file $headerArrLen = count($headerArray); $arrayentry = $headerArrLen - 3; //back 3 to get last session number entry $arrayentry = $arrayentry - 1; //correct number to account for number sys. beggining with 0 //get the old session number and increment it $sessionNum = $headerArray[$arrayentry]; $sessionNum = $sessionNum + 1; //get timestamp-user function $currentDate = makeDate('PHP'); //get referer site if it exists $referer = $_SERVER['HTTP_REFERER']; //put it together for output $addon = '-' . $sessionNum . '-' . $currentDate . '-' . $referer . '-' . $pagename; $everything = $fileLine . $addon; print "alert('To be appended to file : $addon');"; print "alert('File contents after write : $everything');"; //user tracker file is appended with new session date referer and page $fp = fopen($trackFile, 'w'); fwrite($fp, $everything); fclose($fp); } } > --- Fireborn Silvaranth <[EMAIL PROTECTED]> wrote: > > I'm trying to grab a number (sessionNum) out of a text file and increment > > it whenever someone leaves and comes back to the site. > > How about this: > > <? > session_start(); > if (!isset($_SESSION['count'])) > { > $_SESSION['count'] = 0; > } > else > { > $_SESSION['count']++; > } > > echo 'You have visited ' . $_SESSION['count'] . ' times before.'; > ?> > > Chris That's a good way to handle it while they're in the browser but what if they close it and log off then come back on and visit again? I want to track the user as they move through my site, write what pages they go to and when they log onto my site, where they come from and how many times they come. I thought about logging their IP but what good does that do when a lot of people still have dial up? I could set a cookie, and I have tried that, however when I try to access that cookie with PHP upon their return it does not see it. Javascript sees the cookie fine but by then PHP is done processing. It could be that I set the cookie with Javascript but even then PHP still sees it after the page is reloaded or the user browses to the next page. I couldn't set the cookie with PHP because I needed it to occur after checking to see if they had a cookie etc... I tried using output buffering but it still didnt work. I read in the manual that sessions are just meant to last as long as the user is in the browser so I dont know what to do. Your thoughts on this? Learning is fun! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php