02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

202<br />

CHAPTER 6 ■ PASSWORD PROTECTION SENSITIVE ACTIONS AND AREAS<br />

Creating the Admin Class<br />

With your table in place, you can now start structuring the class that will interact with it. In the class<br />

folder, create a new file called class.admin.inc.php (/sys/class/class.admin.inc.php). This class will<br />

contain methods to allow users to log in <strong>and</strong> log out.<br />

Defining the Class<br />

First, you define the class, which will extend DB_Connect in order to have database access. This class will<br />

have one private property, $_saltLength, which you’ll learn about a little later in this section.<br />

The constructor will call the parent constructor to ensure a database object exists, <strong>and</strong> then it will<br />

check whether an integer was passed as the constructor’s second argument. If so, the integer is used as<br />

the value of $_saltLength.<br />

Now insert the following code into class.admin.inc.php to define the class, the property, <strong>and</strong> the<br />

constructor:<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!