Mirabelle Posted July 8, 2006 Share Posted July 8, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/14043-restricting-links-based-on-permission/ Share on other sites More sharing options...
Gast Posted July 8, 2006 Share Posted July 8, 2006 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) ?Niall Quote Link to comment https://forums.phpfreaks.com/topic/14043-restricting-links-based-on-permission/#findComment-54884 Share on other sites More sharing options...
Kurt Posted July 8, 2006 Share Posted July 8, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/14043-restricting-links-based-on-permission/#findComment-54885 Share on other sites More sharing options...
Mirabelle Posted July 8, 2006 Author Share Posted July 8, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14043-restricting-links-based-on-permission/#findComment-54917 Share on other sites More sharing options...
pipeten Posted July 8, 2006 Share Posted July 8, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/14043-restricting-links-based-on-permission/#findComment-54949 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.