File Access Restriction

I am a newbie in PHP and have the assignment of restricting registered users to the files they can have access to. For instance: I have 3 categories of users on the site which are admin, registered users, unregistered users.
Different users with different files they can access. Please do give hint and tutorials that can help on this. Thanks…

How are users infoormation storeed?
Database or flat file?

I will assume you are using database for my answer.
On your dataabase you can have a column called privillege or rank having boolean 1 or 2
Where 1 stands for regular user and 2 for an admin user.
[php]
$query = “SELECT * FROM tableName WHERE username=’”.$_POST[‘txtUsername’]."’ AND password= ‘".$_POST[‘txtPassword’]."’ ;
[/php]
To be continued

[php]
$result = mysql_query($query) or die(“error in query
”.mysql_error());

if (mysql_num_rows($result) > 0){
//sucess login
}else
{
//invalid crendential
}
[/php]

so that is the login to prevent an unauthorized user from seeing a link that he shouldn’t see you do it this way.

[php]
$rows = mysql_fetch_assoc[$query] or die(“errror while mysql_fetch
”.mysql_error());

//only display a link to an loggedin admin
if ($rows[‘rank’] == 2){
echo “Admin”;
}
[/php]

I did not test this you might find some syntax error

good luck and let me know if you get anything working

Sponsor our Newsletter | Privacy Policy | Terms of Service