Page 1 of 1

Restrict Access

Posted: Tue Jun 14, 2011 1:05 pm
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

Re: Restrict Access

Posted: Tue Jun 14, 2011 1:44 pm
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.

Re: Restrict Access

Posted: Fri Jun 17, 2011 9:28 pm
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( );

Re: Restrict Access

Posted: Mon Jun 20, 2011 12:46 pm
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"

Re: Restrict Access

Posted: Mon Jun 20, 2011 1:37 pm
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.