当前位置: 动力学知识库 > 问答 > 编程问答 >

php - Weird elseif behaviour

问题描述:

I want to set a waiting time depending on the phase in which a user is. I just wanted to test this quick and put this:

function towait(){

if ($query = mysql_query('select fase, lastone from users where id = "'.$_SESSION['id'].'"')){

while($r[]=mysql_fetch_array($query));

if ($r[0]['fase'] == 0) {

$wait = 0;

} elseif ($r[0]['fase'] == 1) {

$wait = 300;

} elseif ($r[0]['fase'] == 2) {

$wait = 600;

} elseif ($r[0]['fase'] == 3) {

$wait = 900;

} elseif ($r[0]['fase'] == 4) {

$wait = 1500;

} elseif ($r[0]['fase'] == 5) {

$wait = 2100;

} elseif ($r[0]['fase'] == 6) {

$wait = 2700;

} elseif ($r[0]['fase'] == 7) {

$wait = 3600;

} elseif ($r[0]['fase'] == 8) {

$wait = 5400;

} elseif ($r[0]['fase'] > 8) {

$wait = 7200;

} else {

$wait = 0;

}

if((time() - $r[0]['lastone']) > $wait) {

//go ahead

$go = 1;

} else {

//you have to wait

//I know this looks weird, but I just save the hour when OK to go as a string in the format "HHuMM"

$go = date("H", ($r[0]['lastone'] + $wachten + 60)) . "u" . date("i", ($r[0]['lastone'] + $wachten + 60));

}

return $go;

} else {

$go = -1;

return $go;

}

}

The weird thing is, that everything works perfect until phase 7, but whenever the user is in phase 7, it stops working (the script doesn't let the user wait). The same for phase 8. In phase 9 and 9+ everything works again.

I know it sounds crazy (and the code is written poorly) but I was wondering what could cause this thing.

网友答案:

The most likely explination is that your session times out. This means that, when you return $_SESSION['id'] will be empty and it won't work.

You can increase the session time in php.ini: easiest to read a bblog that explains it all: http://prajapatinilesh.wordpress.com/2009/01/14/manually-set-php-session-timeout-php-session/

分享给朋友:
您可能感兴趣的文章:
随机阅读: