This is what i am trying to make:
You have a website:
To thing can happen:
A guest (not registerd) visites the website. He should get acces to main2.php and not checked on privilege
A user (registerd and logged in) should be checked on privlige. Again 2 things can happen:
Privilege is 4. Then he should NOT get acces to main2.php and get a die(); error
If privilge is not 4, so 1,2,3,5,6, etc, they should get acces to main2.php
Because A guest has no privilege (not registerd), i did
if($privilege != "4")
{
include("main2.php");
That means, anything else then 4 get main2.php Guest that have no privilige, then get main2.php
This is what i am trying to do. But now the problem. Privilege check goes wrong, i think the query is wrong. Everybody have acces to main2.php and users with privilege 4 can thus acces the file.
The data for so far
Picture of database: http://home.wxs.nl/~terps407/tabel.JPG
the file that shoot check the acces:
<?
mysql_connect("localhost","root","");
mysql_select_db("at");
$query = (" SELECT * FROM `user` WHERE `name` = '".mysql_escape_string($_POST['username'])."' AND `password` = (PASSWORD('".mysql_escape_string($_POST['password'])."')) ");
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result))
{
$privilege = $row['privilege'];
}
if($privilege != "4")
{
include("main2.php");
}
else
{
die(test);
}
?>
And finaly the user.php (this is the file wich user use the log in or out. Here you can see how password etc is stored and this information could be needer for the query
<?
require("main.php");
if($action == 'log'){
if($SESSION["loggedin"] == 'Y'){
$sql->query("UPDATE session SET loggedin='N', member='N', hide='N', user='0' WHERE sessid='{$HTTP_COOKIE_VARS["sessid"]}'");
location("index.php");
redirect(3);
} else {
if(isset($username) AND isset($password)){
$fpassword = md5($password);
$query = $sql->query("SELECT user, password FROM user WHERE name='$username'");
print ($sql->num_rows($query) == 0) ? error(4) : NULL;
extract($sql->fetch_assoc($query));
if ($fpassword == $password){
//$sql->query("DELETE FROM session WHERE user='$user'");
//$sql->query("UPDATE session SET loggedin='N', member='N', hide='N', user='0' WHERE user='$user'");
$sql->query("UPDATE session SET loggedin='Y', member='Y', hide='N', user='$user' WHERE sessid='{$HTTP_COOKIE_VARS["sessid"]}'");
if(empty($location)){
location("index.php");
}else{
if(eregi("-", $location)){
$location = explode("-", $location);
$quote = $location[1];
$location = $location[0];
location(base64_decode($location).""e=$quote");
} else {
location(base64_decode($location));
}
}
redirect(7);
}else{
error(47);
}
} else {
//setcookie("sessid", NULL, time()-1);
template("login");
$hf->parseout("main.header1");
if(!empty($location)) $xtpl->parse("main.required");
$xtpl->parseout("main", array('location'=>$location));
$hf->parseout("main.nav_post_off_reply_off");
$hf->parseout("main.footer");
}
}
}
?>
A lot of lines, thx for trying 😉