how can i create a Restricted Area

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
melbourne1815
Forum Newbie
Posts: 13
Joined: Wed Sep 28, 2011 4:01 am

how can i create a Restricted Area

Post by melbourne1815 »

hi i just wanted to know how to create a basic restricted line in or page in php.
Basically my output is this:

Index.php
("You can see the list of users"

"Post Grade"
"Edit my Personal Information"
"My Posted Grades"
"My Personal Messages"
"Logout")

I have a two level of users students and instructors. What i want to happen is that the link "Post Grade" can only be viewed if the instructors is logged in and if the students are logged the link will just be blank.. how can do it? help pls :( :?:
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: how can i create a Restricted Area

Post by Celauran »

A type flag in your user table should suffice.

Code: Select all

if ($user->type == "instructor")
{
	// show "Post grade"
}
else
{
	// don't
}
melbourne1815
Forum Newbie
Posts: 13
Joined: Wed Sep 28, 2011 4:01 am

Re: how can i create a Restricted Area

Post by melbourne1815 »

great! tnks! it really helped me.
I actuall expanded the codes in to this:

Code: Select all

<?php
$req = mysql_query('select username from instructors where username="'.$_SESSION['username'].'"');
$dn = mysql_fetch_array($req);
if(isset($_SESSION['username']) == $dn)
{
	$req=true;
echo '<a href="grade_post.php?">Post Grade</a><br />';
}
else 
{
	echo'';
	}
?>
tnk u i really appreciate it.
Last edited by Benjamin on Wed Sep 28, 2011 6:25 pm, edited 1 time in total.
Reason: Added [syntax=php|sql|css|javascript] and/or [text] tags.
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: how can i create a Restricted Area

Post by Apollo »

Now just hope there is nobody called "; DROP TABLE instructors;# or you'll be screwed :)

(hint: escape stuff before putting it in queries)
Post Reply