Jump to content
Larry Ullman's Book Forums

bem

Members
  • Posts

    2
  • Joined

  • Last visited

bem's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Same as the book for this part to be honest. Been testing it out before I go adding in my own stuff. Works fine when logged in as the Public account and I go to add_page.php I'm redirected to the index page. But if no one is logged in at all and I go to the page I get the error I mentioned above. So my add_page.php has: // Redirect if the user doesn't have permission: if (!$user->canCreatePage()) { header("Location:index.php"); exit; } classes/User.php: class User { // All attributes correspond to database columns. // All attributes are protected. protected $id = null; protected $userType = null; protected $username = null; protected $email = null; protected $pass = null; protected $dateAdded = null; // Method returns the user ID: function getId() { return $this->id; } // Method returns a Boolean if the user is an administrator: function isAdmin() { return ($this->userType == 'admin'); } // Method returns a Boolean indicating if the user is an administrator // or if the user is the original author of the provided page: function canEditPage(Page $page) { return ($this->isAdmin() || ($this->id == $page->getCreatorId())); } // Method returns a Boolean indicating if the user is an administrator or an author: function canCreatePage() { return ($this->isAdmin() || ($this->userType == 'author')); } }
  2. Hi , Followed the chapter fully to test it all out and works well, but when no one is logged in and goes to the add_page.php file a fatal error occurs. Is there a way to correct this when someone isn't logged in? Fatal error: Call to a member function canCreatePage() on a non-object in directory\c09\add_page.php on line 7
×
×
  • Create New...