Restrict Access

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
webdzine
Forum Newbie
Posts: 20
Joined: Wed Dec 08, 2010 12:40 am

Restrict Access

Post by webdzine »

i have a website where i am going to create a demo acct. I want to restrict the access for that demo acct "user" to pages such as changepassword.php
please help. thanks in advance
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Restrict Access

Post by Christopher »

Typically you would store some information in the session, a cookie, or the user's database record that protected pages would check for (and require to be set correctly) before the page would display.
(#10850)
xtiano77
Forum Commoner
Posts: 72
Joined: Tue Sep 22, 2009 10:53 am
Location: Texas

Re: Restrict Access

Post by xtiano77 »

It might not be the best, but here is what I use to restrict access to administrator only pages and then redirect to a neutral page where a message will displayed informing them of what they have done and a warning if they continue. The $_SESSION variable is declared and assigned its value at login and that information come from their profile in the database, so unless they login as an administrator they should not have access to the pages in question. Hope this helps and if you find a more efficient example, please share it with the rest of us.

Code: Select all

public function checkAdministratorAccess( ){
	if($_SESSION["ADMINISTRATOR"] != "yes"){
		# your code here...
		header("Location: http://www.yourpagehere.com");
	}
}

Code: Select all

$userAccess = UserAccess::getInstance( );
$userAccess -> checkAdministratorAccess( );
webdzine
Forum Newbie
Posts: 20
Joined: Wed Dec 08, 2010 12:40 am

Re: Restrict Access

Post by webdzine »

is there the possibility to set up something along the lines of
if user id = "x" then show error code "you have no access to this page"
Peter Kelly
Forum Contributor
Posts: 143
Joined: Fri Jan 14, 2011 5:33 pm
Location: England
Contact:

Re: Restrict Access

Post by Peter Kelly »

If you follow a user system like in the tutorial I have created at

http://www.peter-kelly.com/website-deve ... em-part-1/ and http://www.peter-kelly.com/website-deve ... em-part-2/

I have included ways that you can limit access per account or if there not logged in. If you have a look at that you should be able to see how I have done this and take example from this.
Post Reply