SaLz
asked on
I would like to see, which pages visitors went to on my website.
Hi!
I would like to see, which pages visitors went to on my website. It would somehow get the page's name and path, and add it ( if it doesn't exist yet ) to where user's IP matches the current user.
It would then display the stats for each day like so:
29.08.2005
IP: 206.27.86.101
Pages visited:
index.php,
files/test.php
----------------
IP: 210.22.35.96
Pages visited:
index.php,
files/new.php
----------------
28.08.2005
IP: 206.27.86.101
Pages: ...
And maybe show what pages are most visited ( top 5 ).
How can that be done ? code wise please.
Thank you,
Sal
I would like to see, which pages visitors went to on my website. It would somehow get the page's name and path, and add it ( if it doesn't exist yet ) to where user's IP matches the current user.
It would then display the stats for each day like so:
29.08.2005
IP: 206.27.86.101
Pages visited:
index.php,
files/test.php
----------------
IP: 210.22.35.96
Pages visited:
index.php,
files/new.php
----------------
28.08.2005
IP: 206.27.86.101
Pages: ...
And maybe show what pages are most visited ( top 5 ).
How can that be done ? code wise please.
Thank you,
Sal
ASKER
ok.. now how can that be done code wise ? :)
ASKER
btw, mysql is the DB it should go to, ya.
Maybe you find something here:
http://www.proxy2.de/scripts.php
http://www.proxy2.de/scripts.php
ASKER
nope, nothing there, thank you for trying to help angel,
but i would rather see how it can be done :)
but i would rather see how it can be done :)
Salz, want me to add this sort of thing to my other script i made up for you?
ASKER
heya neester!
yeah please do :)
yeah please do :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you neester! I'm trying it out now. :)
I got this error,
on this line:
if (mysql_num_rows($qCheckIfE xisting) > 0) {
it's Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
by the way, i updated the code a little, instead of visitor_complete, i added a Date field and am checking if there is a record for today's date, like so:
$PAGE_URL=addslashes($_SER VER['REQUE ST_URI']);
$qCheckIfExisting=mysql_qu ery("SELEC T visitor_id FROM visitors WHERE Date='".date('Y-m-d')."' AND visitor_ip='$REMOTE_ADDR' ");
if (mysql_num_rows($qCheckIfE xisting) > 0) {
// Exisitng User
$visID=mysql_fetch_array($ qCheckIfEx isting);
$visID=$visID['visitor_id' ];
mysql_query("UPDATE visitors SET visitor_last_hit=".time(). ", visitor_hits=visitor_hits+ 1 WHERE visitor_ip='$REMOTE_ADDR' AND Date='".date('Y-m-d')."'") ;
mysql_query("INSERT INTO visitor_pages (visitor_id,page_url,page_ time) VALUES ($visID,'$PAGE_URL',".time ().")");
}else{
// New User
mysql_query("INSERT INTO visitors (visitor_hits,visitor_firs t_hit) VALUES (1,".time().")");
$visID=mysql_insert_id();
mysql_query("INSERT INTO visitor_pages (visitor_id,page_url,page_ time) VALUES ($visID,'$PAGE_URL',".time ().")");
}
can you see why it comes up with an error, maybe i messed something up ? :/
I got this error,
on this line:
if (mysql_num_rows($qCheckIfE
it's Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource
by the way, i updated the code a little, instead of visitor_complete, i added a Date field and am checking if there is a record for today's date, like so:
$PAGE_URL=addslashes($_SER
$qCheckIfExisting=mysql_qu
if (mysql_num_rows($qCheckIfE
// Exisitng User
$visID=mysql_fetch_array($
$visID=$visID['visitor_id'
mysql_query("UPDATE visitors SET visitor_last_hit=".time().
mysql_query("INSERT INTO visitor_pages (visitor_id,page_url,page_
}else{
// New User
mysql_query("INSERT INTO visitors (visitor_hits,visitor_firs
$visID=mysql_insert_id();
mysql_query("INSERT INTO visitor_pages (visitor_id,page_url,page_
}
can you see why it comes up with an error, maybe i messed something up ? :/
Ahh yeah, you can't just call a CELL date.
$qCheckIfExisting=mysql_qu ery("SELEC T visitor_id FROM visitors WHERE >>Date<<='".date('Y-m-d'). "' AND visitor_ip='$REMOTE_ADDR' ");
See the arrows >> <<
Date is a MYSQL Function.
To fix that, simply change it to this:
$qCheckIfExisting=mysql_qu ery("SELEC T visitor_id FROM visitors WHERE visitors.Date='".date('Y-m -d')."' AND visitor_ip='$REMOTE_ADDR' ");
So it knows you mean the Field DATE.
:D
$qCheckIfExisting=mysql_qu
See the arrows >> <<
Date is a MYSQL Function.
To fix that, simply change it to this:
$qCheckIfExisting=mysql_qu
So it knows you mean the Field DATE.
:D
BTW you will need to make that change wherever you have Date in the Query.
:)
:)
ASKER
ohh, of course! thank you hehe.
but for some reason it still gives the same error
but for some reason it still gives the same error
ASKER
also, here's the table info, everything should be ok:
SQL query:
CREATE TABLE `visitors` (
`visitor_id` INT( 15 ) NOT NULL AUTO_INCREMENT ,
`visitor_ip` VARCHAR( 20 ) NOT NULL ,
`visitor_hits` INT( 5 ) NOT NULL ,
`visitor_first_hit` TIME NOT NULL ,
`visitor_last_hit` TIME NOT NULL ,
`Date` DATE NOT NULL ,
PRIMARY KEY ( `visitor_id` )
) TYPE = MYISAM ;
SQL query:
CREATE TABLE `visitor_pages` (
`visitor_id` INT( 15 ) NOT NULL ,
`page_url` VARCHAR( 255 ) NOT NULL ,
`page_time` TIME NOT NULL
) TYPE = MYISAM ;
SQL query:
CREATE TABLE `visitors` (
`visitor_id` INT( 15 ) NOT NULL AUTO_INCREMENT ,
`visitor_ip` VARCHAR( 20 ) NOT NULL ,
`visitor_hits` INT( 5 ) NOT NULL ,
`visitor_first_hit` TIME NOT NULL ,
`visitor_last_hit` TIME NOT NULL ,
`Date` DATE NOT NULL ,
PRIMARY KEY ( `visitor_id` )
) TYPE = MYISAM ;
SQL query:
CREATE TABLE `visitor_pages` (
`visitor_id` INT( 15 ) NOT NULL ,
`page_url` VARCHAR( 255 ) NOT NULL ,
`page_time` TIME NOT NULL
) TYPE = MYISAM ;
ASKER
ah nm, was having some trouble with the database, i had to recreate the tables now, it works :)
ok, i'll try displaying the stats now. I'll let you know how it goes :)
ok, i'll try displaying the stats now. I'll let you know how it goes :)
ASKER
i have updated the code a little, we forgot to update ip and time.
I'll post it here a bit later, but i have to run for a while, so i'll get back to ya when i get back :)
take care till then,
Sal
I'll post it here a bit later, but i have to run for a while, so i'll get back to ya when i get back :)
take care till then,
Sal
Hey mate,
Good to see you got it working!
You are using MySQL Time/Date functions which I didn't originally plan on using - although its fine, it still works the same.
Cheers,
- Chris
Good to see you got it working!
You are using MySQL Time/Date functions which I didn't originally plan on using - although its fine, it still works the same.
Cheers,
- Chris
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Chris, hi gerodim.
ya i just added the date and ip insertion:
$PAGE_URL=addslashes($_SER VER['REQUE ST_URI']);
$qCheckIfExisting=mysql_qu ery("SELEC T visitor_id FROM visitors WHERE visitors.Date='".date('Y-m -d')."' AND visitor_ip='$REMOTE_ADDR' "); echo mysql_error();
if (mysql_num_rows($qCheckIfE xisting) > 0) {
// Exisitng User
$visID=mysql_fetch_array($ qCheckIfEx isting);
$visID=$visID['visitor_id' ];
mysql_query("UPDATE visitors SET visitor_last_hit=".time(). ", visitor_hits=visitor_hits+ 1 WHERE visitor_ip='$REMOTE_ADDR' AND visitors.Date='".date('Y-m -d')."'");
mysql_query("INSERT INTO visitor_pages (visitor_id,page_url,page_ time) VALUES ($visID,'$PAGE_URL',".time ().")");
}else{
// New User
mysql_query("INSERT INTO visitors (visitor_ip,visitor_hits,v isitor_fir st_hit,vis itors.Date ) VALUES ('$REMOTE_ADDR',1,".time() .",'".date ('Y-m-d'). "')");
$visID=mysql_insert_id();
mysql_query("INSERT INTO visitor_pages (visitor_id,page_url,page_ time) VALUES ($visID,'$PAGE_URL',".time ().")");
}
i'll mess with it more and post any followups on it :)
Thank you,
Sal
ya i just added the date and ip insertion:
$PAGE_URL=addslashes($_SER
$qCheckIfExisting=mysql_qu
if (mysql_num_rows($qCheckIfE
// Exisitng User
$visID=mysql_fetch_array($
$visID=$visID['visitor_id'
mysql_query("UPDATE visitors SET visitor_last_hit=".time().
mysql_query("INSERT INTO visitor_pages (visitor_id,page_url,page_
}else{
// New User
mysql_query("INSERT INTO visitors (visitor_ip,visitor_hits,v
$visID=mysql_insert_id();
mysql_query("INSERT INTO visitor_pages (visitor_id,page_url,page_
}
i'll mess with it more and post any followups on it :)
Thank you,
Sal
Then, when you need the report, just issue a query like this:
SELECT Page, count(*) from logtable group by page order by count(*) LIMIT 1,5