bumba000 Posted January 28, 2008 Share Posted January 28, 2008 Hi all, Thanks for reading! Ive been watching the mysql & php training vid from 3DBuzz for a while now. Still having some problems. Sure would appreciate a bit of help with this. . . Need my script to track page views per ip. I dont care what page it is and I dont need to query any of this from an admin. If the IP/user has viewed 1 page then they are shown $var1 if this is the 2nd page they have viewed they are shown $var2 and so on up to 5. Once they have viewed a total of 5 pages and been shown all $vars 1-5 their count needs to empty and start over so we can go through the $vars again. I have a few different versions of this tracker script running. I havent been able to come up with one that will track and update as needed. Any help is greatly appreciated. Thanks in advance, John if you need any other info please let me know. Quote Link to comment https://forums.phpfreaks.com/topic/88142-trying-to-write-a-tracker/ Share on other sites More sharing options...
Bauer418 Posted January 28, 2008 Share Posted January 28, 2008 The problem with just using a session for something this simple is? Quote Link to comment https://forums.phpfreaks.com/topic/88142-trying-to-write-a-tracker/#findComment-450985 Share on other sites More sharing options...
bumba000 Posted January 28, 2008 Author Share Posted January 28, 2008 HUH? Quote Link to comment https://forums.phpfreaks.com/topic/88142-trying-to-write-a-tracker/#findComment-451001 Share on other sites More sharing options...
Bauer418 Posted January 28, 2008 Share Posted January 28, 2008 session_start(); $_SESSION['var'] = isset($_SESSION['var']) && $_SESSION['var'] <= 5 ? ($_SESSION['var'] + 1) : 1; $_SESSION['var'] will now cycle from 1-5 then back to 1 Quote Link to comment https://forums.phpfreaks.com/topic/88142-trying-to-write-a-tracker/#findComment-451007 Share on other sites More sharing options...
bumba000 Posted January 28, 2008 Author Share Posted January 28, 2008 Hey! Thanks! I am trying to understand this an in my db in already using a table called sessions. will that bother anything? I have a script put together now that will make an entry into a table called ccounter that has 2 fields they are IP and page. This is working. I can run that in any page and see that it is being tracked. I can also echo out the results and see that its working. I can not get it to reset to 0 after it hits 5. Now the reply above, can you explain this please and how to fit it into my code or tell me how to reconfigure what ive got to work please. Ill paste what ive got below in a min. I have it on another comp. Thanks, John Quote Link to comment https://forums.phpfreaks.com/topic/88142-trying-to-write-a-tracker/#findComment-451032 Share on other sites More sharing options...
bumba000 Posted January 28, 2008 Author Share Posted January 28, 2008 <?php require($_SERVER["DOCUMENT_ROOT"] . "/1_3_2008_Test_Site/includes/configure.php"); $connection = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD) or die(mysql_error()); mysql_select_db(DB_DATABASE, $connection); $this_page = $_SERVER["PHP_SELF"]; $IP = $_SERVER["REMOTE_ADDR"]; $query = "INSERT INTO ccounter (page, IP) VALUES ('$this_page', '$IP')"; mysql_query($query, $connection); echo "<br>IP views:<br>"; $query = "SELECT *, count(*) FROM ccounter GROUP BY IP"; $result = mysql_query($query, $connection); for ($i = 0; $i < mysql_num_rows($result); $i++) { //$page = mysql_result($result, $i, "page"); $IP = mysql_result($result, $i, "IP"); $views = mysql_result($result, $i, "count(*)"); echo "$IP "; echo "views: $views<br>"; } $cur_IP = $_SERVER["REMOTE_ADDR"]; $query = DELETE FROM `ccounter` WHERE CONVERT(`ccounter`.`IP` USING utf8) = '$cur_IP' AND CONVERT(`ccounter`.`page` USING utf8) = '/1_3_2008_Test_Site/Untitled-2.php' LIMIT 1; mysql_query($query, $connection) or die(mysql_error()); ?> Quote Link to comment https://forums.phpfreaks.com/topic/88142-trying-to-write-a-tracker/#findComment-451033 Share on other sites More sharing options...
bumba000 Posted January 28, 2008 Author Share Posted January 28, 2008 That table name is session not sessions. Quote Link to comment https://forums.phpfreaks.com/topic/88142-trying-to-write-a-tracker/#findComment-451036 Share on other sites More sharing options...
bumba000 Posted January 28, 2008 Author Share Posted January 28, 2008 OKAY!!!! WOW I guess thank you very much! yeah this does work. Exactly what I was trying to do with all that mess above! Thanks, John Quote Link to comment https://forums.phpfreaks.com/topic/88142-trying-to-write-a-tracker/#findComment-451039 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.