Jump to content

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!
Link to comment
https://forums.phpfreaks.com/topic/14043-restricting-links-based-on-permission/
Share on other sites

[code]
$result=mysql_query("SELECT link From tbl WHERE link=1");
if(mysql_num_rows($result)>=1){
//echo out the links
}else{
die('You do not have permission to be here!');
}
[/code]

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.
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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.