Page 1 of 1

Logs....

Posted: Sat Aug 24, 2002 12:05 pm
by Dale
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?

Posted: Sat Aug 24, 2002 2:21 pm
by hob_goblin

Code: Select all

foreach($_SERVER as $value){
// log $value
}

Posted: Sat Aug 24, 2002 2:28 pm
by Takuma
I have read the manual of foreach but i still don't understand. Could anyone tell me how you use it, when you use it and how does it work? please....

Posted: Sat Aug 24, 2002 2:56 pm
by hob_goblin
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
}

Posted: Sat Aug 24, 2002 3:11 pm
by volka
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

Posted: Sat Aug 24, 2002 3:54 pm
by Takuma
Thank you... :D

Posted: Sat Aug 24, 2002 4:11 pm
by Dale
eh???

In the header of every page is this:

Code: Select all

<?php 
    $agent = $_SERVER&#1111;'HTTP_USER_AGENT']; 
    $uri = $_SERVER&#1111;'REQUEST_URI']; 
    $user = $_SERVER&#1111;'PHP_AUTH_USER']; 
    $ip = $_SERVER&#1111;'REMOTE_ADDR']; 
    $ref = $_SERVER&#1111;'HTTP_REFERER']; 
    $dtime = date('r'); 
     
    if($ref == "")&#123; 
        $ref = "None"; 
    &#125; 
    if($user == "")&#123; 
        $user = "None"; 
    &#125; 
     
    $entry_line = "-=&#1111; $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); 
?>
So whats that code thing about then and where do i insert it...

Posted: Sat Aug 24, 2002 4:26 pm
by hob_goblin

Code: Select all

<?
$message = date('r')."\n";
foreach($_SERVER as $key => $value)&#123;
$message .= $key," :",$value,"\n";
&#125;
$message .= "\n";

    $fp = fopen("/usr/local/etc/httpd/dale.unrealism.com/logs.txt", "a"); 
    fputs($fp, $message); 
    fclose($fp); 

?>

Posted: Sun Aug 25, 2002 4:31 am
by Dale
Thx M8 ;)

Posted: Sun Aug 25, 2002 4:42 am
by Dale
Parse error: parse error, unexpected ',' in /usr/local/etc/httpd/dale.unrealism.com/menu.php on line 4
Line 4:

Code: Select all

$message .= $key," :",$value,"\n";

Posted: Sun Aug 25, 2002 4:48 am
by hob_goblin

Code: Select all

$message .= $key." :".$value."\n";
sorry

Posted: Sun Aug 25, 2002 4:50 am
by Dale
Neat Script!


Is there a way of adding:
===============================================
At the bottom.. so it seperates them in the TXT file?

Posted: Sun Aug 25, 2002 6:35 am
by theChosen

Code: Select all

<? 
$message = date('r')."\n"; 
foreach($_SERVER as $key => $value)&#123; 
$message .= $key." :".$value."\n"; 
&#125; 
$message.="=======================================\n";
$message .= "\n"; 

    $fp = fopen("/usr/local/etc/httpd/dale.unrealism.com/logs.txt", "a"); 
    fputs($fp, $message); 
    fclose($fp); 

?>
parts (c) hob_goblin :)
also check
http://www.php.net/manual/en/function.str-pad.php
http://www.php.net/manual/en/function.str-repeat.php

Posted: Mon Aug 26, 2002 10:13 am
by Dale
Cheers ;)