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.
$query = “SELECT * FROM tableName WHERE username=’”.$_POST[‘txtUsername’]."’ AND password= ‘".$_POST[‘txtPassword’]."’ ;
To be continued

$result = mysql_query($query) or die(“error in query

if (mysql_num_rows($result) > 0){
//sucess login
//invalid crendential

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

$rows = mysql_fetch_assoc[$query] or die(“errror while mysql_fetch

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

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