Jump to content

Recommended Posts

I am close to distraction!

I have the following code:

[code]$mintime = 15;
now = time();
$timediff = ($now - $_SESSION["StartTime"] + 1);
$newdate = $newdate.' - '.$timediff.' - '.$now.' - '.$_SESSION["StartTime"];
[/code]
The date as it is usually displayed, looks like this:
date=25.07.2006 13:55 - 4 - 1153828543 - 1153828540

When the time difference between $now and the previously stored $_SESSION["StartTime"] is zero, the display looks like this, although I have added one to hat difference:
date=25.07.2006 14:04 - 1153829072 - 1153829071 -

I cannot see why $timediff , which cannot be less than one, is not being displayed.

That the other twp variables move forward by one position, still remains a true mystery.

There must be a trivial explanation for this!

Link to comment
https://forums.phpfreaks.com/topic/15577-there-are-no-mysteries-are-there/
Share on other sites

your problem might be somewhere else in your code...
try this:
[code]
if(isset($_SESSION["StartTime"])){
  $mintime = 15;
  now = time();
  $timediff = ($now - $_SESSION["StartTime"] + 1);
  $newdate = $newdate.' - '.$timediff.' - '.$now.' - '.$_SESSION["StartTime"];
}
[/code]

Make sure at the top of your page your initializing the session with session_start()
[quote]The variable $_SESSION["StartTime"] is either not set or is empty in the second case, and therefore the line

$timediff = ($now - $_SESSION["StartTime"] + 1);

evaluates to $now + 1.[/quote]

Thanks for that, It seems indeed, to be the case.

But if

[code]session_start();
$_SESSION["StartTime"] = time();[/code]

cannot be relied upon to create $_SESSION["StartTime"] , what is the alternative?

You can dump any array with any one of the following functions: var_dump(), var_export(), or print_r(). I prefer print_r(), although var_export() is also handy.

I use something like:
[code]<?php
function dumpit($arr,$title='')
{
    if (!empty($arr)) echo '<pre>' . $title . print_r($arr,true) . '</pre>';
}
?>[/code]

Ken
Thank you Ken for that useful assistance. I don't believe I could have found it on my own.

I fear that interest in my problem is waning, but I have some more information, which hasn't cleared up a lot - not for me. at least.

My code (in file new.html.inc)
[code]session_start();
$_SESSION["StartTime"] = time();
if(isset($_SESSION["StartTime"])) { echo 's'; }[/code]

reproducibly displays a character s, indicating that $_SESSION has been created.


The code (in file input.php)
[code]session_start();
$mintime = 15;
$check = time();
$duration = ($check - $_SESSION["StartTime"]);
$admin01 = 'duration was '.$duration;
$admin02 = 'check time was '.$check;
$admin03 = 'start time was '.$_SESSION["StartTime"];
$admin04 = ' ';
if (!empty($_SESSION)) $admin04 = print_r($_SESSION,true);[/code]

later in the processing, often shows that $_SESSION exists:
date=27.07.2006 19:34
- duration was 1
- check time was 1154021699
- start time was 1154021698
- Array
(
    [StartTime] => 1154021698
)


but not always:
date=27.07.2006 19:38
- duration was 1154021938
- check time was 1154021938
- start time was
-

So it has the appearance that the previous session is not always being resumed. What can be the cause of that?

Working only now and then is actually worse than not working at all.

[code]$mintime = 15;
now = time();
$timediff = ($now - $_SESSION["StartTime"] + 1);
$newdate = $newdate.' - '.$timediff.' - '.$now.' - '.$_SESSION["StartTime"];[/code]

^^^ You're not signing now as a variable at the top:

[code]$mintime = 15;
$now = time();
$timediff = ($now - $_SESSION["StartTime"] + 1);
$newdate = $newdate.' - '.$timediff.' - '.$now.' - '.$_SESSION["StartTime"];[/code]

Is how it should be :P

Thanks -- king arthur:
Are you calling session_start() twice somehow? Or unsetting the $_SESSION variable somewhere?

Yes - called once at the start of each processing of the session (in different files). The manual says that it's necessary to resume the session.


Thanks -- dark dude:
^^^ You're not signing now as a variable at the top:

Oh dear - that was a editing error.  "now" is written $now" in the code. Sorry.

"signing as a variable"? I never declare variables at the outset in PH
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.