0

I want to use time in pagination.In my script when click on next the timer restarts..i think session will help me.but i don't understand how to collect correct time in session and display that in another page in pagination.This is my javascript code:

var myTime = "20";

function countDown() {
    document.form.seconds.value = myTime;
    if (myTime == 0)
    {
        location.href="abc.php";
    }
    else if (myTime > 0)
    {
        myTime--;
        setTimeout("countDown()",2000);
    }
}

and this is how i set the time in my php file:

<form name="form">
    Time Left: <input type="text" name="seconds" size="3">
</form>
Imran Omer
  • 701
  • 1
  • 8
  • 20

1 Answers1

0

Using session is really very simple. Just include: session_start(); at the beginning of every PHP file of your script.

Then, in order to set a time variable, use this: $_SESSION['theTime'] = $currentDateTime;

where $currentDateTime = date('m/d/Y h:i:s a', time());

Now, this $_SESSION['theTime'] variable will be passed on to every PHP file if you include session_start(); at the beginning of each. To find out difference between two times, refer this: php: datetime() difference between 2 datetime with 2 variables

Community
  • 1
  • 1
Lavneet
  • 516
  • 5
  • 19