Jump to content

Server time in unreadable format


Strac72

Recommended Posts

I am using this php to write to a text file to show me who has logged in and when:

<?php
$time = $_SERVER['REQUEST_TIME'];
$myusername = $_POST['myusername'];

$data = "$REQUEST_TIME\n";
$data = "$myusername\n";


//open the file and choose the mode
$fh = fopen("logs/login.txt", "a") ;

fwrite($fh, $data);
fwrite($fh, $time);
fclose($fh);

?>

The result I get in my text file is:

paul
1315919200melody
1315919221tracy&graham
1315919232ed&hannah
1315919251

I would feel more successful if the name of the user were to appear on the next line down but I can live with that but I can't make head nor tale of the date.

I want it to say:
paul
13:59
13/09/2011

next user
14:00
13/09/2011 and so on

I feel I have done very well to even get that far really and wouldn't have been able to yesterday. I am frustrated to have reached the extent of my current understanding.

 

If anyone can tell me where I'm going wrong, that would be great.

 

I hope the php isn't too far off, and you can "read between the lines" as it were to see what I'm trying to do.

 

Paul

 

MOD EDIT: code tags added.

 

Link to comment
https://forums.phpfreaks.com/topic/247043-server-time-in-unreadable-format/
Share on other sites

After a few hours and a lot of swearing, I ended up with this:

 


<?php
date_default_timezone_set('GMT+01.00');

$date = date(r);
$myusername = $_POST['myusername'];


$data = "$myusername\n";
$date = "$date\n";

$fh = fopen("logs/login.txt", "a") ;

fwrite($fh, $data);
fwrite($fh, $date);
fclose($fh);

?>

 

Which has worked, apart from the timezone bit, which still reads as an hour behind. Bloomin' BST. It'll be over in a few weeks! Give a dog a bone!  8)

Thanks Pikachu. I gleaned that I'd have to use

date_default_timezone_set('Europe/London');

which automatically added the +1 hour I was looking for. I hope it changes back at Halloween or whenever it is.

On the road to perfection, I tried creating a $ that was blank to insert a line break into the text file, I tried

 $blank = '<br />';

and then asking it to

fwrite($fh, $blank);

but that hasn't worked. Don't really know how to term it for a web search. Crikey, my brain aches!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.