I am unable to find anyone that is able to do that. So i open another thread and ask again.
I wan a script that is able to capture the follwing info
Wednesday, 10 December 2003 02:31 pm 202.156.x.xx0 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) http://forums.hardwarezoom.com/showthread.php?s=&threadid=2069
and i wan the script to generate a new log for a each new day.
It you wan to use SQL, it is ok with me. I know SQL can store and retrieve data faster and easier.
pyro
12-13-2003, 02:32 PM
Ok, try something like this. Here's the SQL to create the database table. I used a database named iplogger.
CREATE TABLE `log` (
`id` int(11) NOT NULL auto_increment,
`time` int(11) NOT NULL default '0',
`ip` varchar(20) NOT NULL default '',
`user_agent` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
)
Next, insert this on to any of the pages that you want to log the ip/user agent for:
# get first date
$sql = "SELECT * FROM `log` ORDER BY `time` ASC LIMIT 1";
$results = mysql_query($sql);
$time = mysql_fetch_array($results);
$mintime = $time['time'];
$mintime = mktime(0,0,0,date("m,d,year",$mintime));
# get latest date
$sql = "SELECT * FROM `log` ORDER BY `time` DESC LIMIT 1";
$results = mysql_query($sql);
$time = mysql_fetch_array($results);
$maxtime = $time['time'];
$maxtime = mktime(0,0,0,date("m,d,year",$maxtime));
PHP to read info:
<?PHP
mysql_connect('localhost','username','password');
mysql_select_db('iplogger');
# get first date
$sql = "SELECT * FROM `log` ORDER BY `time` ASC LIMIT 1";
$results = mysql_query($sql);
$time = mysql_fetch_array($results);
$mintime = $time['time'];
$mintime = mktime(0,0,0,date("m,d,year",$mintime))-1;
# get latest date
$sql = "SELECT * FROM `log` ORDER BY `time` DESC LIMIT 1";
$results = mysql_query($sql);
$time = mysql_fetch_array($results);
$maxtime = $time['time'];
$maxtime = mktime(0,0,0,date("m,d,year",$maxtime));
$sql = "SELECT * FROM `log` WHERE `time` > $beg AND `time` < $end";
$results = mysql_query($sql);
if (mysql_num_rows($results) > 0) {
while($data = mysql_fetch_array($results)) {
echo " <tr>\n"
." <td>".date("l, d F Y h:i a", $data['time'])."</td>\n"
." <td>".$data['ip']."</td>\n"
." <td>".$data['user_agent']."</td>\n"
." <td>".$data['referrer']."</td>\n"
." </tr>\n";
}
}
else {
echo " <tr>\n"
." <td colspan=\"4\">No results found</td>\n"
." </tr>\n";
}
?>
</table>
</body>
</html>
tanfwc
12-14-2003, 07:12 PM
ty veri much...i try later
tanfwc
12-14-2003, 09:21 PM
ty...it work wonderful...
pyro
12-14-2003, 10:22 PM
You are welcome. :)
tanfwc
12-15-2003, 07:34 AM
erm....ask you hor...will the ip address be recorded double if i put the code all around the webby?
pyro
12-15-2003, 07:36 AM
Yes, it will be recoreded for every hit.
tanfwc
12-15-2003, 07:46 AM
Originally posted by pyro
Yes, it will be recoreded for every hit.
can i prevent the ip address from recording twice?
pyro
12-15-2003, 10:24 AM
Ever, per day, or with a set amount of time (such as 1 hour)?
tanfwc
12-15-2003, 08:49 PM
Originally posted by pyro
Ever, per day, or with a set amount of time (such as 1 hour)?
hmm...10 min?
pyro
12-15-2003, 10:38 PM
Ok, here's what you will want to do... (You will only need to modify the page that writes the data.)
First, get the IP address. Then run an SQL query to check if that IP is in the DB, and if so, what the latest timestamp is. Now, get the current time, and make sure it is 10 mins more than the time in the DB. If it is, run the query to insert the info.
tanfwc
12-15-2003, 10:40 PM
Originally posted by pyro
Ok, here's what you will want to do... (You will only need to modify the page that writes the data.)
First, get the IP address. Then run an SQL query to check if that IP is in the DB, and if so, what the latest timestamp is. Now, get the current time, and make sure it is 10 mins more than the time in the DB. If it is, run the query to insert the info.
ok. I am a SQL newbie, pls explain. Thanx.
pyro
12-15-2003, 10:43 PM
$sql = "SELECT `time` FROM `log` WHERE `ip` = '$ip' ORDER BY `time` DESC LIMIT 1";
tanfwc
12-15-2003, 10:45 PM
now i have to insert this code into my current code izzit?
pyro
12-15-2003, 10:47 PM
Yep, look at all the code that I've given you so far, and see if you can get close.
tanfwc
12-15-2003, 10:49 PM
Originally posted by pyro
Yep, look at all the code that I've given you so far, and see if you can get close.
ok. Let me try first...then i feedback to u...
pyro
12-15-2003, 10:51 PM
Good. I definitely prefer helping people if they make a genuine effor to learn. When they assume that I have nothing better to do that customize and tweak a script to their liking, I have no desire to continue helping them. I'm herer to spread what knowledge I have (and learn things, when I can), not make custom script for free. :)
tanfwc
12-15-2003, 11:16 PM
omg...hv been try here and there....still keep logging the same ip address...i am having a headache now...
pyro
12-16-2003, 07:08 AM
Post you code, and we'll go from there.
tanfwc
12-16-2003, 07:42 AM
hmmm...you know what....got myself a idea...i only apply that code on the index page. The rest of the page i just call the ip code...
pyro
12-16-2003, 07:43 AM
huh? :confused:
tanfwc
12-16-2003, 07:55 AM
Originally posted by pyro
huh? :confused:
coz in the first place i apply all the code to all the pages, that mean if the visitor go to another page, the ip will be capture so i just apply the code you give me to the main page and the rest of the page, i just use $ip lor...ty veri much for ur help.
pyro
12-16-2003, 08:02 AM
Still not sure what you mean, but that's ok. As long as you know... :)
Anyway, happy to help. :cool:
tanfwc
12-16-2003, 08:07 AM
Originally posted by pyro
Still not sure what you mean, but that's ok. As long as you know... :)
Anyway, happy to help. :cool:
sorry for my bad english. Anyway, great to meet you.
can you guide me how to use php to insert "additional" code to more than 10 html page? Coz now it is chrisitian and i wan all the page to have snow. Then when new year, i have hong bao floating. I dun not waste to edit page by page.
pyro
12-16-2003, 08:11 AM
include (http://us2.php.net/manual/en/function.include.php) should work nicely for that.
tanfwc
12-16-2003, 08:20 AM
ok. i quite blur. That mean, i mean to put
<?
include 'file.txt';
?>
to add in the additional code to my web site izzit?
then i just create a txt file and put in the require code izzit?
pyro
12-16-2003, 08:20 AM
Yes.
tanfwc
12-16-2003, 08:23 AM
Originally posted by pyro
Yes.
so....i just learn myself something new...
TY...
pyro
12-16-2003, 09:56 AM
You bet. :)
tanfwc
12-16-2003, 12:52 PM
i have another problem...i am currently having a midi file been played when a visitor visit my webby. i notice that the midi file stop playing when a visitor click on another links to my other webby. How to overcome this problem? maybe u can guide me again so that i can learn something new again.
pyro
12-16-2003, 12:59 PM
You really only have a few options, none of them as desirable as getting rid of the MIDI iteself (background music is usually annoying).
1 - Use frames, where one frame will not change, and contains the background music. A horrible method, as you will then have a frames site.
2 - Open a popup that controls the music. Not much (if any) better than option 1.
3 - Make a flash site. (And remember, for accessibility reasons, you will also need to upkeep a static site.)
Overall, there is no good way to get around this. But, as I said, I would recommend dropping the background sound altogether.
tanfwc
12-16-2003, 01:01 PM
Originally posted by pyro
You really only have a few options, none of them as desirable as getting rid of the MIDI iteself (background music is usually annoying).
1 - Use frames, where one frame will not change, and contains the background music. A horrible method, as you will then have a frames site.
2 - Open a popup that controls the music. Not much (if any) better than option 1.
3 - Make a flash site. (And remember, for accessibility reasons, you will also need to upkeep a static site.)
Overall, there is no good way to get around this. But, as I said, I would recommend dropping the background sound altogether.
hmm...but my visitor love the music...ok...i go for method two...any guide for me?
pyro
12-16-2003, 01:03 PM
Look at http://www.webdevfaqs.com/javascript.php#popup and then embed your background music in the page that that window loads.
tanfwc
12-16-2003, 01:06 PM
Originally posted by pyro
Look at http://www.webdevfaqs.com/javascript.php#popup and then embed your background music in the page that that window loads.
ty...i try it tml morning...erm...one more qns...remember the include qns? should i use php or txt version? which is better?
pyro
12-16-2003, 01:16 PM
I usually use PHP, but it (usually) does not matter.
tanfwc
12-16-2003, 06:25 PM
Originally posted by pyro
I usually use PHP, but it (usually) does not matter.
ok then. I follow the professional.
tanfwc
12-16-2003, 07:34 PM
Originally posted by pyro
Look at http://www.webdevfaqs.com/javascript.php#popup and then embed your background music in the page that that window loads.
how to open a pop up automatically? do u know any music control script?
tanfwc
12-16-2003, 08:21 PM
i think i need to have ur help for the ip address logging...after trial run for a few days, the script still log LOT of same ip address and the refeer is the same(when the visitor view my index page again)...so can guide me on how to use SQL? this time teach me...
pyro
12-16-2003, 09:46 PM
I'm trying to help you learn, but these are complex languages, and you won't be picking them up over the course of a few days. I'd recommend picking up some good books on the subject(s) and starting by designing some simple scripts.
Anyway, I believe I described what you would want to do earlier, so I'm assuming you couldn't figure it out from that.
Originally posted by pyro
I'm trying to help you learn, but these are complex languages, and you won't be picking them up over the course of a few days. I'd recommend picking up some good books on the subject(s) and starting by designing some simple scripts.
Anyway, I believe I described what you would want to do earlier, so I'm assuming you couldn't figure it out from that.
$sql = "SELECT `time` FROM `log` WHERE `ip` = '$ip' ORDER BY `time` DESC LIMIT 1"; #check if the users IP is in the DB (and if so, grap that latest timestamp)
$results = mysql_query($sql);
if (mysql_num_rows($results) != 0) { #if a row was returned
$loggedtime = mysql_fetch_array($results);
$loggedtime = $loggedtime[0]; #set to the latest time the user was on the page
}
if ($loggedtime+$mins*60 < time()) { #in english: if (the last timestamp we have for this use + the desired number of minutes * 60 is less than the current time)
$sql = "INSERT INTO `log` (`id`, `time`, `ip`, `user_agent`, `referrer`)
VALUES ('', '$time', '$ip', '$user_agent', '$referrer')";
mysql_query($sql);
}
?>
tanfwc
12-16-2003, 10:11 PM
Originally posted by pyro
Yes, that is very close to what it says. Here's some comments:
$sql = "SELECT `time` FROM `log` WHERE `ip` = '$ip' ORDER BY `time` DESC LIMIT 1"; #check if the users IP is in the DB (and if so, grap that latest timestamp)
$results = mysql_query($sql);
if (mysql_num_rows($results) != 0) { #if a row was returned
$loggedtime = mysql_fetch_array($results);
$loggedtime = $loggedtime[0]; #set to the latest time the user was on the page
}
if ($loggedtime+$mins*60 < time()) { #in english: if (the last timestamp we have for this use + the desired number of minutes * 60 is less than the current time)
$sql = "INSERT INTO `log` (`id`, `time`, `ip`, `user_agent`, `referrer`)
VALUES ('', '$time', '$ip', '$user_agent', '$referrer')";
mysql_query($sql);
}
?>
Ok. Thank you. I can understand more now.
pyro
12-16-2003, 10:13 PM
You are welcome. :)
tanfwc
12-16-2003, 10:16 PM
Originally posted by pyro
You are welcome. :)
Can i link your webby from my site? coz u helped me alot. So some credit must go to u.
and one more thing....
is there anyway to edit this code to read data from
$sql = 'SELECT * FROM `count_total` WHERE 1 LIMIT 0, 30';
As far as your other query, I'm not sure what it is that you are asking...
tanfwc
12-16-2003, 10:50 PM
Originally posted by pyro
Yes, please feel free to link to my site. :)
As far as your other query, I'm not sure what it is that you are asking...
Ok. Maybe this here (http://proxy2.de/scripts.php) link can help you...(look under Animated Counter 1.1)
this script use text file to store the data. But i have Daily Counter 1.1(same web site) installed also. Daily counter use db to store data. I would like to have the animated counter 1.1 to read daily counter data(there is a table in db that has total visitor).
pyro
12-16-2003, 10:55 PM
That would probably be a fair amount of work - probably more than can be expected to be done on a fourms that simply exists to help people with their coding problems.
tanfwc
12-16-2003, 11:02 PM
Originally posted by pyro
That would probably be a fair amount of work - probably more than can be expected to be done on a fourms that simply exists to help people with their coding problems.
then it ok lor. Nvm then.
tanfwc
01-20-2004, 10:00 AM
Originally posted by pyro
Ok, try something like this. Here's the SQL to create the database table. I used a database named iplogger.
CREATE TABLE `log` (
`id` int(11) NOT NULL auto_increment,
`time` int(11) NOT NULL default '0',
`ip` varchar(20) NOT NULL default '',
`user_agent` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
)
Next, insert this on to any of the pages that you want to log the ip/user agent for:
# get first date
$sql = "SELECT * FROM `log` ORDER BY `time` ASC LIMIT 1";
$results = mysql_query($sql);
$time = mysql_fetch_array($results);
$mintime = $time['time'];
$mintime = mktime(0,0,0,date("m,d,year",$mintime));
# get latest date
$sql = "SELECT * FROM `log` ORDER BY `time` DESC LIMIT 1";
$results = mysql_query($sql);
$time = mysql_fetch_array($results);
$maxtime = $time['time'];
$maxtime = mktime(0,0,0,date("m,d,year",$maxtime));