angribirdi
angribirdi

Reputation: 39

date() when page load and after submiting form

I'm making an registration page and I want to get the timestamp from (A) when the page is loaded and (B) when the form is submited.

In my script I have placed the (A) date("Y-m-d H:i:s"); first in the script and (B) date("Y-m-d H:i:s"); inside the if(isset...)

The problem is that the first date() gets deleted and replaced with the stamp from when I submit the form - and (A) and (B) gets the same.

Is there any way to get this to work simple? Or must I use cookies for an example?

--

This is an example code:

<?php

$timepageload = date("Y-m-d H:i:s"); 

    if(isset($_POST['action'])) {

                $timewhensubmited = date("Y-m-d H:i:s"); 

        }

?>

Upvotes: 0

Views: 44

Answers (1)

Ali
Ali

Reputation: 3081

There are a couple of approaches you can choose.

The most strait-forward one is to include a hidden field in your form which is holding the timestamp.

This actually will be the timestamp A, and the timestamp B can be obtain as you are doing right now.

Upvotes: 1

Related Questions