Jump to content


Photo

There are no mysteries! Are there?


  • Please log in to reply
10 replies to this topic

#1 bgsomers

bgsomers
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 25 July 2006 - 12:32 PM

I am close to distraction!

I have the following code:

$mintime = 15;
now = time();
$timediff = ($now - $_SESSION["StartTime"] + 1); 
$newdate = $newdate.' - '.$timediff.' - '.$now.' - '.$_SESSION["StartTime"];
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!



#2 lead2gold

lead2gold
  • Members
  • PipPipPip
  • Advanced Member
  • 164 posts
  • LocationOttawa, On

Posted 25 July 2006 - 12:41 PM

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

Make sure at the top of your page your initializing the session with session_start()


#3 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 25 July 2006 - 12:42 PM

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.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#4 bgsomers

bgsomers
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 26 July 2006 - 08:07 PM

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.


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

But if

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

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



#5 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 26 July 2006 - 09:46 PM

Well there's nothing wrong with that so the problem must lie somewhere else!
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#6 bgsomers

bgsomers
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 27 July 2006 - 10:56 AM

Is there a way to display the entire contents of an array whose structure is not known?

$_SESSION for example?

#7 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 27 July 2006 - 11:40 AM

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:
<?php
function dumpit($arr,$title='')
{
    if (!empty($arr)) echo '<pre>' . $title . print_r($arr,true) . '</pre>';
}
?>

Ken

#8 bgsomers

bgsomers
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 27 July 2006 - 06:35 PM

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)
session_start();
$_SESSION["StartTime"] = time();
if(isset($_SESSION["StartTime"])) { echo 's'; }

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


The code (in file input.php)
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);

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.



#9 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 27 July 2006 - 09:33 PM

Are you calling session_start() twice somehow? Or unsetting the $_SESSION variable somewhere?
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#10 dark dude

dark dude
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts

Posted 27 July 2006 - 10:36 PM

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

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

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

Is how it should be :P

#11 bgsomers

bgsomers
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 28 July 2006 - 08:20 AM


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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users