Forum Moderators: coopster

Message Too Old, No Replies

If you ever want to know...

where your last visitor came from...

         

dmorison

8:29 pm on May 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<?php

$last_line_of_log = exec("tail /path/to/access_log");

$ip = substr($last_line_of_log,0,strpos($last_line_of_log," "));

$host = exec("host ".$ip);

echo "<font face='courier'> $host </font>";

?>

I was bored.

chris_f

11:38 am on May 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Simpler in ASP

Response.Write(Request.ServerVariables("HTTP_REFERER"))

Chris :)

dmorison

5:45 am on May 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Chris,

That PHP hack displays the host name associated with the IP address of the last entry in the web server logfile (if reverse DNS is configured for their IP) - not the referrer field value...

BCMG_Scott

11:34 am on May 14, 2003 (gmt 0)

10+ Year Member



I beleive tail actually returns the last 10 lines so you actually are getting the 10th to the last visitor with that (as the 10th to the last line will be first).

tail -n 1 /path/to/access_log will give the last line.

Scott Geiger

dmorison

12:21 pm on May 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Scott,

- tail does indeed return more than one line, but the PHP exec() function returns only the last line of output from the command called.

BCMG_Scott

12:45 pm on May 14, 2003 (gmt 0)

10+ Year Member



hmmmm - interesting, guess that shows how often I use php's exec() function :-P

Thanks for the info.

Scott

bonanza

1:08 pm on May 14, 2003 (gmt 0)



Cool script.

Hmm, I get the IP ok but the host command output doesn't display. need to do a little more debugging, probably not finding the host command on my virtual server.

Warning: Don't put this script on the server that you're checking. Unless of course you're the type who likes to see yourself in the mirror. ;)

dmorison

1:29 pm on May 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmm, I get the IP ok but the host command output doesn't display. need to do a little more debugging, probably not finding the host command on my virtual server.

What do you actually get? If it's just blank it would imply that the "host" command cannot be found in the path of the user that your web server is running as (or you don't have the host command installed). I'm running Redhat Linux 7.1, with Apache running as its own user - "apache" - i've done nothing special over the stock installation.

Warning: Don't put this script on the server that you're checking. Unless of course you're the type who likes to see yourself in the mirror. ;)

Ahah! Unless you knock up some mechanism so that your own requests are not logged...

[webmasterworld.com...]

bonanza

1:49 pm on May 14, 2003 (gmt 0)



What do you actually get?

yeah, I get nothing. I'm fairly certain that the web user's not finding the host command. It's a bit more complicated than path issues as it's a virtual server and the web user sees a different root directory than I see when I'm logged into the server.

Thanks for the tip on keeping myself out of the logs,
but I like to look at myself in the mirror ;)

Seriously, I find it more beneficial to see my own hits vs. not. And I do have another virtual host on the server with different access_logs to run this script from.

TheWebographer

2:04 pm on May 14, 2003 (gmt 0)

10+ Year Member



Very interesting...

How would you modify your script to show, say, the last 100 requests for pages (not gifs etc)?

dmorison

8:42 pm on May 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How would you modify your script to show, say, the last 100 requests for pages (not gifs etc)?

shell_exec("tail -n 100 /path/to/access_log") would return the complete output of the last 100 lines of your log.

You could then split() the output into an array of single lines and then loop through the array doing the same process as described above on each line.

Look in this thread for my post about supressing logging of images and other boring stuff...

[webmasterworld.com...]