Jump to content

Recommended Posts

everytime a user who's logged in refreshes the control panel, I need to update the timestamp in the database for the user... but it wont update... can anyone see what might be causing it?

 

this is the validation function I run on top of every page:

<?php

function valUser($epost)
{
	$axx = $_COOKIE['axx'];
	$sid = $_COOKIE['sid'];
	if (!empty($axx) && !empty($sid)) {
		c2db();
		$epost = secureSQL($epost);
		$axx = secureSQL($axx);
		$sid = secureSQL($sid);
		$query = "
			SELECT * FROM `news_users` WHERE
				`email` = '".$epost."'
			AND
				`access` = '".$axx."'
			AND
				`sid` = '".$sid."'
			AND
				`authorized` = '1'
			LIMIT 1
		";
		$result = mysql_query($query);
		if (!$result) { die(mysql_error()); }

		$dbRows = mysql_num_rows($result);
		if ($dbRows == 1) {
			$dbField = mysql_fetch_array($result);
			$last_active = strtotime($dbField['timestamp']);
			$idle = strtotime(date("Y-m-d H:i:s", strtotime("5 minutes ago")));
			if ($idle > $last_active) {
				setcookie("epost", "", time()-3600);
				setcookie("axx", "", time()-3600);
				setcookie("sid", "", time()-3600);
				return 0;
			} elseif ($idle < $last_active) {
				updateTimestamp($epost,$axx,$sid);
				return 1;
			}
		} else { header("Location: index.php"); }		

	}

}

?>

 

this is the updateTimestamp() function

<?php
function updateTimestamp($epost,$axx,$sid)
{

	c2db();
	$new_time = secureSQL(date("Y-m-d H:i:s"));
	$epost = secureSQL($epost);
	$axx = secureSQL($axx);
	$sid = secureSQL($sid);
	$query = "
		UPDATE `news_users` SET 
			`timestamp` = '".$new_time."'
		WHERE
			`email` = '".$user."'
		AND
			`sid` = '".$sid."'
		AND
			`access` = '".$axx."'
		LIMIT 1
	";
	$result = mysql_query($query);
	if (!$result) { die(mysql_error()); }

	setcookie("epost", "", time()-3600);
	setcookie("axx", "", time()-3600);
	setcookie("sid", "", time()-3600);
	setcookie("epost", $epost, time()+3600);
	setcookie("axx", $axx, time()+3600);
	setcookie("sid", $sid, time()+3600);
}
?>

 

this is what I run on top of every page

<?php
if (isset($_COOKIE['epost']) && !empty($_COOKIE['epost'])) {
	$epost = $_COOKIE['epost'];
	$valUser = valUser($epost);
	if ($valUser == 0) { header("Location: index.php"); }
} else { header("Location: index.php"); }
?>

 

Thanks In Advance

- Clown

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.