Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/88142-trying-to-write-a-tracker/
Share on other sites

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

<?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());


?>

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.