Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #15138
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Newsgroups | comp.lang.php |
| Subject | Re: dans un log.txt : reduire IP à deux octets selon recomm CNIL |
| Date | Sat, 28 Mar 2015 22:47:53 +0100 |
| Organization | PointedEars Software (PES) |
| Lines | 52 |
| Message-ID | <13863983.OW5F8XF2sQ@PointedEars.de> (permalink) |
| References | <5516e98a$0$2988$426a34cc@news.free.fr> <9RCRw.180861$jx4.20363@fx27.iad> |
| Reply-To | Thomas 'PointedEars' Lahn <php@PointedEars.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Trace | solani.org 1427579388 15989 eJwNysEBwCAIA8CVEEjEcRBw/xHaex+Mi7WdoOPhaawisXVuvnPUZSryL6ezKTYmjZCLorUEPhaAENA= (28 Mar 2015 21:49:48 GMT) |
| X-Complaints-To | abuse@news.solani.org |
| NNTP-Posting-Date | Sat, 28 Mar 2015 21:49:48 +0000 (UTC) |
| User-Agent | KNode/4.14.2 |
| X-User-ID | eJwNxsEBwCAIA8CVQAjCOIpk/xHaex0sNHp7IBwEdczzNGr+1ttD0dcLqaxrY5D72gtSyw/HSAihasg7GvEBY5gVmg== |
| Cancel-Lock | sha1:Lnhbj54ZK3lM/ZvuQyN7u2yj3fk= |
| X-NNTP-Posting-Host | eJwNyMkBACAIA7CV5GjFcRBl/xE0z8AorOkEHY3W2OFbtK9kKZalhDCGXsLAE+wzlpGsv54PCHsQGA== |
| Xref | csiph.com comp.lang.php:15138 |
Show key headers only | View raw
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.
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
dans un log.txt : reduire IP à deux octets selon recomm CNIL bird <new.bird@free.fr> - 2015-03-28 18:48 +0100
Re: dans un log.txt : reduire IP à deux octets selon recomm CNIL Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-03-28 14:58 -0400
Re: dans un log.txt : reduire IP à deux octets selon recomm CNIL Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-03-28 22:47 +0100
in a log.txt : how convert IP.IP.IP.IP to IP.IP.*.* (hope of french CNIL) ? bird <new.bird@free.fr> - 2015-03-31 10:52 +0200
Re: in a log.txt : how convert IP.IP.IP.IP to IP.IP.*.* (hope of french CNIL) ? Jerry Stuckle <jstucklex@attglobal.net> - 2015-03-31 09:16 -0400
Re: in a log.txt : how convert IP.IP.IP.IP to IP.IP.*.* (hope of french CNIL) ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-03-31 22:28 +0200
Re: dans un log.txt : reduire IP à deux octets selon recomm CNIL Thomas Mlynarczyk <thomas@mlynarczyk-webdesign.de> - 2015-03-28 20:15 +0100
Re: dans un log.txt : reduire IP à deux octets selon recomm CNIL Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-03-28 22:50 +0100
csiph-web