drdapoo Posted September 5, 2007 Share Posted September 5, 2007 Hello I am trying to make a script that allows me to validate and figure out if there session has timed out, all using timestamps. I think this piece of code is whats causing the problem. Could anyone with fresh eyes tell me if there are any errors? <?php if(isset($HTTP_COOKIE_VARS('time') && ($HTTP_COOKIE_VARS('session_ID')))){ if($HTTP_COOKIE_VARS('time') > time()){ include 'myconnectionscript.php'; $query = "select date from usertable WHERE session_id='$HTTP_COOKIE_VARS('session_ID')'"; mysql_close($db); $rownumber = mysql_numrows($query); if($rownumber > 0){ $result = mysql_result($query, $rownumber, 'date'); if($result > time()){ } }else{header('Location: http://www.mysite.com/loginpage.php');} }else{header('Location: http://www.mysite.com/loginpage.php');} }else{header('Location: http://www.mysite.com/loginpage.php');} ?> Peace EDIT: Found one small error but its still spitting up problems. Link to comment https://forums.phpfreaks.com/topic/68141-solved-validating-users-error/ Share on other sites More sharing options...
syntaxerror Posted September 5, 2007 Share Posted September 5, 2007 quick note here, at first glance i noticed that you have isset( $var1 && $var2 ) and i thought the syntax was isset($var1, $var2) Link to comment https://forums.phpfreaks.com/topic/68141-solved-validating-users-error/#findComment-342513 Share on other sites More sharing options...
drdapoo Posted September 5, 2007 Author Share Posted September 5, 2007 quick note here, at first glance i noticed that you have isset( $var1 && $var2 ) and i thought the syntax was isset($var1, $var2) Well I thought that by adding the && it would force the user to log in if neither of the fields have any data in them. Was the way I did it wrong? Link to comment https://forums.phpfreaks.com/topic/68141-solved-validating-users-error/#findComment-342515 Share on other sites More sharing options...
Jessica Posted September 6, 2007 Share Posted September 6, 2007 if(isset($var1) && isset($var2)) or the way syntax posted. Yes, the way you did is wrong, it should have given you an error Turn on error reporting. Link to comment https://forums.phpfreaks.com/topic/68141-solved-validating-users-error/#findComment-342534 Share on other sites More sharing options...
drdapoo Posted September 6, 2007 Author Share Posted September 6, 2007 Ok I fixed the first problem but now I am getting the fallowing error PHP Fatal error: Can't use function return value in write context in C:\\Web_Server\\blah on line 3 So basicly the whole point of line 3 is to see if the client even has a cookie from my site. Now it seems I cant check with the current code. Does anyone know exactly how I can check to see if they have a cookie without getting this error? Link to comment https://forums.phpfreaks.com/topic/68141-solved-validating-users-error/#findComment-342692 Share on other sites More sharing options...
teng84 Posted September 6, 2007 Share Posted September 6, 2007 $HTTP_COOKIE_VARS('time') should be $HTTP_COOKIE_VARS['time'] $query = "select date from usertable WHERE session_id='$HTTP_COOKIE_VARS('session_ID')'"; should be $query = "select date from usertable WHERE session_id='".$HTTP_COOKIE_VARS['session_ID']."'"; or $query = "select date from usertable WHERE session_id='{$HTTP_COOKIE_VARS['session_ID']}'"; Link to comment https://forums.phpfreaks.com/topic/68141-solved-validating-users-error/#findComment-342704 Share on other sites More sharing options...
drdapoo Posted September 6, 2007 Author Share Posted September 6, 2007 Ok so here is my code now <?php $time = time(); if(isset($HTTP_COOKIE_VARS['time'] && (isset($HTTP_COOKIE_VARS['session_ID'])))) { if($HTTP_COOKIE_VARS['time'] > $time) { include 'mydatabaseconnection.php'; $query = "select time from usertable WHERE session_id='$HTTP_COOKIE_VARS['bb']'"; mysql_close($db); $rownumber = mysql_numrows($query); if($rownumber > 0) { $result = mysql_result($query, $rownumber, 'time'); if($result > $time) { } else { header('Location: http://www.mysite.com/login.php'); } } else { header('Location: http://www.mysite.com/login.php'); } } else { header('Location: http://www.mysite.com/login.php'); } } else { header('Location: http://www.mysite.com/login.php'); } ?> Now it is spitting out an error PHP Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ',' or ')' on line 3 I thought I had all my ) in order but it looks like I dont. I just cant seem to find out whats wrong. Link to comment https://forums.phpfreaks.com/topic/68141-solved-validating-users-error/#findComment-342847 Share on other sites More sharing options...
chocopi Posted September 6, 2007 Share Posted September 6, 2007 if(isset($HTTP_COOKIE_VARS['time'] && (isset($HTTP_COOKIE_VARS['session_ID'])))) should be if(isset($HTTP_COOKIE_VARS['time']) && isset($HTTP_COOKIE_VARS['session_ID'])) ~ Chocopi Link to comment https://forums.phpfreaks.com/topic/68141-solved-validating-users-error/#findComment-342863 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.