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
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)

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.