Problem with FreeBSD using fwrite() function???
| From: | Matt Moreton | Date: | Mon, 11 Feb 2002 22:32:20 +0000 |
| Subject: | Problem with FreeBSD using fwrite() function??? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-84315@lists.php.net to get a copy of this message | ||
Firstly, thanks to all those that helped me with my "fooling the client into thinking php
script is .jpg". I am using ForceType method to do that at the moment. My admin is looking
into mod_rewrite for me though.
Ok here's the problem.
I made a script that logs the IP address of the client. $REMOTE_ADDR and it also takes a timestamp
in UNIX format.
I then split the 4 parts of the IP address...
$ipsub = explode( ".", $REMOTE_ADDR );
This is then packed into a binary string...
$LogLine = pack( "LS4", $TimeStamp, $ipsub[0], $ipsub[1], $ipsub[2], $ipsub[3] );
The timestamp is converted into a long unsigned integer taking up 32bits, and the following 4 parts
of the IP address are converted into short unsigned integers taking up 16bits.
That is then written to a file using:
$fp = @fopen($LogFile, "ab");
if ( $fp ) {
@fwrite( $fp, $LogLine );
@fclose( $fp );
}
However, when I go to read the logfile and decode it using another script. It seems scrambled.
Like the data didnt save properly. It decodes properly, reports the correct timestamp and ip
address whern I try running it on my development machine (Win2k, php4.1.1). On my linux webserver
it is also fine. But when I try it on my FreeBSD/php4.1.0 website, the results are not as expected.
The IP and timestamp are way off.
I have tried a little script to just pack the data, then unpack it, without saving to disk, and it
works fine, so I know for sure it is a problem with the fwrite() function.
Any ideas to why this is happening? Any solutions please? Im really stuck!
Thanks
Matt.