Lew Pitcher wrote:
> […] "bird" […] wrote:
>> //fwrite($fp, "$time $ip $page $browser");
> fwrite($fp, "$time $ip[0].$ip[1] $page $browser");
The log file created by this code will be unreadable and hardly parseable
because it will have only one long line: the trailing newline of each entry
is missing – fwrite() does not write it by default.
As for the rest, I recommend to use braces, concatenation, or (v)sprintf()
to avoid ambiguities –
fwrite($fp, "{$time} {$ip[0]}.{$ip[1]} {$page} {$browser}\n");
or
fwrite($fp, $time . ' ' . $ip[0] . '.' . $ip[1] . ' ' . $page
. ' ' . $browser . "\n");
or
fwrite($fp,
vsprintf("{$time} %s.%s {$page} {$browser}\n",
array_slice(explode('.', $_SERVER['REMOTE_ADDR']), 0, 2)));
or
fwrite($fp,
sprintf("%s %s.%s %s %s\n", $time, $ip[0], $ip[1], $page, $browser));
(in this simple case I would probably use braces, if only for “$ip[0]” and
“$ip[1]” to make clear that there is no concatenation. But note that Web
servers already can write such log files in a non-blocking fashion; there is
hardly a need to reinvent the wheel in a worse way) – …
>> fclose($fp);
>> //-------------------------------------------------------------
>>
>> comment réduire l'ip nnnn.mmm.oooo.pppp à nnnn.mmm ?
>>
>> merci
… and, although and because this is an international newsgroup, to post here
in English only (in order to reach the widest possible audience), and to
post in French to <news:fr.comp.lang.php> instead.
--
PointedEars
Zend Certified PHP Engineer
Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.