Jump to content

Recommended Posts

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

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?

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?

$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']}'";  ;)

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.

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.