Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

storing some information into a text file using PHP. 1

Status
Not open for further replies.

rossmcl

Programmer
Apr 18, 2000
128
Hi

I am brand new to PHP, trying to do something very quickly so I can store some basic information on visitors hitting my site. I have no idea about PHP, and have strung the below very quickly (and amateurishly) together.

But I am getting errors (surprisingly enough!)

I would REALLY appreciate if someone could take a quick perusal and debug for me. It will take me several hours of reading php.net to work out what is wrong, but I am sure one of you can do it in minutes!! Not trying to be lazy, honest guvnor...but my 'talents' lie elsewhere...!

=====

<?php
$filename = &quot;PHPStoreVisitorInfo.txt&quot;;
$handle = fopen ($filename, &quot;a+&quot;);

$todaydate = strval((date(&quot;m.d.y&quot;));
$todaytime = strval(time())
$visitorInfo = $HTTP_SERVER_VARS['REMOTE_ADDR'] \r\n ;

fwrite( $handle, $todaydate + $todaytime + $visitorInfo );
fclose( $handle );
?>

====

All I want to do is concatentate strings for todays date AND todays time AND the IP address from visitors remote machine, and put it into a row in a text file. Then I want to create a new line (I believe the \r\n does that, so that next time I come back to the txt file, I will be appending a new line to the txt file (I believe the a+ in file open function will take me to this new line (?)

As I say, any help in debugging this for me would be very much appreciated. Dont want to spend ages learning PHP, when its only a very simple thing I need to be able to do with PHP for my website (at the moment). In the meantime, would prefer to leave it to the experts...YOU!

Thanks
RM
 
PHP's string concatenation operator is &quot;.&quot;, not &quot;+&quot;.

Since date() can return both the date and time (using a format like &quot;Y-m-d H:i:s&quot; will return &quot;2003-12-15 16:56:00&quot;, for example) in a single string, you don't need to invoke time().

The use of strval() with date() is unnecessary -- date() returns a string. strval() is unnecessary under most situations because PHP is pretty good at type casting.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top