Jump to content


This topic is now archived and is closed to further replies.


Restricting links based on permission

Recommended Posts

Forgive me as I am a ColdFusion person trying to learn PHP.

I have created a login script.  Anyone can login to see the page, however, I want to only display certain links if the user has permission to view them.

In the MySQL database, I have a field called "link" just for testing purposes.  It has a "1" for permission and a "0" for no permission.

In Coldfusion, one line of code does this for me but I don't think I can convert it to work with the PHP language.

Any help would be appreciated.  Thank you!

Share this post

Link to post
Share on other sites
Are you trying to restrict the viewing of the link to whether it is 1 or 0 in the database or for a particular type of user (say a regular user or an administrator) ?


Share this post

Link to post
Share on other sites
$result=mysql_query("SELECT link From tbl WHERE link=1");
//echo out the links
die('You do not have permission to be here!');

Try this. I don't know how you keep track of logged in users but you will have to modify that query to where it selects from the table where the user is logged in as well as link equals 1.

Share this post

Link to post
Share on other sites
Perhaps I am not approaching this the best way but I'll explain what I am trying to do:

I wanted to create a field in the "users" table for each link that is going to be restricted.

Here is my table structure that I was going to use:

create table users (
uid int not null primary key auto_increment,
username char(16) not null,
password char(16) not null,
post tinyint not null default '1',
reply tinyint not null default '1,
edit tinyint not null default '0',
delete tinyint not null default '0'

If the value is set to 1, the link would be displayed for the user.  If the value is set to 0, the link would not be displayed.

This way, instead of making usergroups which manage the permissions, I can just edit the user directly.

I am using sessions by the way.  Feel free to let me know if I shouldn't be doing it this way.  Again, this is my first PHP/MySQL project.

Share this post

Link to post
Share on other sites
That's fine. You can do it that way but it doesn't allow for much expansion (depending upon future requirements). I'd consider storing permissions in a seperate table.

If your using sessions obviously don't retain the password there too.

Share this post

Link to post
Share on other sites


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.