I’ve heard that people can edit cookies and change their name and access level (etc.), so I coded a simple PHP code to prevent them from editing their user’s properties (such as access level). Here it is:
doConnect();
$currentIP = $_SERVER['REMOTE_ADDR'];
$page = "geton";
$AHQuery = mysql_query("SELECT * FROM users WHERE user='{$_SESSION['uName']}' ORDER BY id DESC");
while($AHLine = mysql_fetch_array($AHQuery)) {
$trueIP = $AHLine['ip'];
$trueLevel = $AHLine['acesslevel'];
}
if($currentIP != $trueIP || $_SESSION['uAcessLevel'] != $trueLevel) {
echo "<script>alert('Please, login again.'); location.href='{$page}'</script>";
exit;
}
The code above checks if the session user (X USER) is a valid name and if it equals to the latest X USER’s ip (when you login your ip is gathered and saved in the users table), if it doesn’t then the session is destroyed and the user is forced to login again. Anyway, my question is: is this method safe, does it really prevent people from viewing private pages and commenting as another user? (this function is in every single page of my php forumblog) Is there a better and safer way to do this?
I tried to be as clear as possible, hope you guys understand it, thanks for your attention.