Skip to content

Code example: Authorizing users

jbroadway edited this page Oct 5, 2011 · 2 revisions

Here is a simple bit of code you can use to authorize users:

<?php

if (! User::require_login ()) {
	$page->title = i18n_get ('Members');
	echo $this->run ('user/login');
	return;
}

// members-only stuff goes here

?>

To do the same for admin pages, you would use:

<?php

// use the admin layout (optional)
$page->layout = 'admin';

if (! User::require_admin ()) {
	$this->redirect ('/admin');
}

// admin-only stuff goes here

?>

Clone this wiki locally