Jump to content


Photo

Restricting links based on permission


  • Please log in to reply
4 replies to this topic

#1 Mirabelle

Mirabelle
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 08 July 2006 - 07:58 PM

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!

#2 Gast

Gast
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts
  • LocationSouth East England

Posted 08 July 2006 - 08:02 PM

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
OS and Internet Specs:
Windows XP (with SP2), 1680x1050, PHP 4, MySQL 3, Internet Explorer 6 &7 /FireFox 2.0/Opera 9.2

Tutorials:
Simple Introduction to AJAX and XMLHttpRequest
Creating Live Data with AJAX Making a Google Suggest like application

#3 Kurt

Kurt
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts
  • LocationNew York

Posted 08 July 2006 - 08:02 PM

$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!');
}

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.

#4 Mirabelle

Mirabelle
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 08 July 2006 - 08:49 PM

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.

#5 pipeten

pipeten
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 08 July 2006 - 10:07 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users