bgsomers Posted July 25, 2006 Share Posted July 25, 2006 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 - 1153828540When 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! Quote Link to comment https://forums.phpfreaks.com/topic/15577-there-are-no-mysteries-are-there/ Share on other sites More sharing options...
lead2gold Posted July 25, 2006 Share Posted July 25, 2006 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 Link to comment https://forums.phpfreaks.com/topic/15577-there-are-no-mysteries-are-there/#findComment-63347 Share on other sites More sharing options...
king arthur Posted July 25, 2006 Share Posted July 25, 2006 The variable $_SESSION["StartTime"] is either not set or is empty in the second case, and therefore the line[code]$timediff = ($now - $_SESSION["StartTime"] + 1);[/code]evaluates to $now + 1. Quote Link to comment https://forums.phpfreaks.com/topic/15577-there-are-no-mysteries-are-there/#findComment-63348 Share on other sites More sharing options...
bgsomers Posted July 26, 2006 Author Share Posted July 26, 2006 [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? Quote Link to comment https://forums.phpfreaks.com/topic/15577-there-are-no-mysteries-are-there/#findComment-64295 Share on other sites More sharing options...
king arthur Posted July 26, 2006 Share Posted July 26, 2006 Well there's nothing wrong with that so the problem must lie somewhere else! Quote Link to comment https://forums.phpfreaks.com/topic/15577-there-are-no-mysteries-are-there/#findComment-64345 Share on other sites More sharing options...
bgsomers Posted July 27, 2006 Author Share Posted July 27, 2006 Is there a way to display the entire contents of an array whose structure is not known?$_SESSION for example? Quote Link to comment https://forums.phpfreaks.com/topic/15577-there-are-no-mysteries-are-there/#findComment-64582 Share on other sites More sharing options...
kenrbnsn Posted July 27, 2006 Share Posted July 27, 2006 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]<?phpfunction dumpit($arr,$title=''){ if (!empty($arr)) echo '<pre>' . $title . print_r($arr,true) . '</pre>';}?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/15577-there-are-no-mysteries-are-there/#findComment-64606 Share on other sites More sharing options...
bgsomers Posted July 27, 2006 Author Share Posted July 27, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/15577-there-are-no-mysteries-are-there/#findComment-64754 Share on other sites More sharing options...
king arthur Posted July 27, 2006 Share Posted July 27, 2006 Are you calling session_start() twice somehow? Or unsetting the $_SESSION variable somewhere? Quote Link to comment https://forums.phpfreaks.com/topic/15577-there-are-no-mysteries-are-there/#findComment-64847 Share on other sites More sharing options...
dark dude Posted July 27, 2006 Share Posted July 27, 2006 [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 Quote Link to comment https://forums.phpfreaks.com/topic/15577-there-are-no-mysteries-are-there/#findComment-64864 Share on other sites More sharing options...
bgsomers Posted July 28, 2006 Author Share Posted July 28, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/15577-there-are-no-mysteries-are-there/#findComment-65044 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.