Logs....
Moderator: General Moderators
Logs....
I have a little thing that logs who comes on my site and heres what it record's:
$agent = $_SERVER['HTTP_USER_AGENT'];
$uri = $_SERVER['REQUEST_URI'];
$user = $_SERVER['PHP_AUTH_USER'];
$ip = $_SERVER['REMOTE_ADDR'];
$ref = $_SERVER['HTTP_REFERER'];
Question...
Are there anymore things that can be added in the top bit?
$agent = $_SERVER['HTTP_USER_AGENT'];
$uri = $_SERVER['REQUEST_URI'];
$user = $_SERVER['PHP_AUTH_USER'];
$ip = $_SERVER['REMOTE_ADDR'];
$ref = $_SERVER['HTTP_REFERER'];
Question...
Are there anymore things that can be added in the top bit?
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
Code: Select all
foreach($_SERVER as $value){
// log $value
}- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
it loops thru every value of an array...
Code: Select all
$array = array(
"one" => "1",
"two" => "2");
foreach($array as $value){
echo $value;
// would print "12"
}
foreach($array as $key => $value){
echo $key,$value;
//would print one1two2
}each time you add something to an array it is simply appended (or replaced if the index already existed) no matter what the index was.
$arr = array();
$arr[4] = "a"; // $arr <-> [ 4=> "a"]
$arr[1] = "b"; // $arr <-> [ 4=> "a", 1=>"b"]
and so on...
using print_r you can see this each()-order
foreach walk the array in this each()-order assigning in each iteration the current entry value to a variable (or with '...as $key=>$value' the index as well) and executes the loop-body
$arr = array();
$arr[4] = "a"; // $arr <-> [ 4=> "a"]
$arr[1] = "b"; // $arr <-> [ 4=> "a", 1=>"b"]
and so on...
using print_r you can see this each()-order
foreach walk the array in this each()-order assigning in each iteration the current entry value to a variable (or with '...as $key=>$value' the index as well) and executes the loop-body
eh???
In the header of every page is this:
So whats that code thing about then and where do i insert it...
In the header of every page is this:
Code: Select all
<?php
$agent = $_SERVERї'HTTP_USER_AGENT'];
$uri = $_SERVERї'REQUEST_URI'];
$user = $_SERVERї'PHP_AUTH_USER'];
$ip = $_SERVERї'REMOTE_ADDR'];
$ref = $_SERVERї'HTTP_REFERER'];
$dtime = date('r');
if($ref == ""){
$ref = "None";
}
if($user == ""){
$user = "None";
}
$entry_line = "-=ї $dtime ]=-
Agent: $agent
IP: $ip
URL: $uri
Referrer: $ref
\n";
$fp = fopen("/usr/local/etc/httpd/dale.unrealism.com/logs.txt", "a");
fputs($fp, $entry_line);
fclose($fp);
?>- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
Code: Select all
<?
$message = date('r')."\n";
foreach($_SERVER as $key => $value){
$message .= $key," :",$value,"\n";
}
$message .= "\n";
$fp = fopen("/usr/local/etc/httpd/dale.unrealism.com/logs.txt", "a");
fputs($fp, $message);
fclose($fp);
?>Line 4:Parse error: parse error, unexpected ',' in /usr/local/etc/httpd/dale.unrealism.com/menu.php on line 4
Code: Select all
$message .= $key," :",$value,"\n";- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
Code: Select all
$message .= $key." :".$value."\n";Code: Select all
<?
$message = date('r')."\n";
foreach($_SERVER as $key => $value){
$message .= $key." :".$value."\n";
}
$message.="=======================================\n";
$message .= "\n";
$fp = fopen("/usr/local/etc/httpd/dale.unrealism.com/logs.txt", "a");
fputs($fp, $message);
fclose($fp);
?>also check
http://www.php.net/manual/en/function.str-pad.php
http://www.php.net/manual/en/function.str-repeat.php