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.

214<br />

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

* Enable sessions<br />

*/<br />

session_start();<br />

/*<br />

* Include necessary files<br />

*/<br />

include_once '../../../sys/config/db-cred.inc.php';<br />

/*<br />

* Define constants for config info<br />

*/<br />

foreach ( $C as $name => $val )<br />

{<br />

define($name, $val);<br />

}<br />

/*<br />

* Create a lookup array for form actions<br />

*/<br />

$actions = array(<br />

'event_edit' => array(<br />

'object' => 'Calendar',<br />

'method' => 'processForm',<br />

'header' => 'Location: ../../'<br />

),<br />

'user_login' => array(<br />

'object' => 'Admin',<br />

'method' => 'processLoginForm',<br />

'header' => 'Location: ../../'<br />

)<br />

);<br />

/*<br />

* Make sure the anti-CSRF token was passed <strong>and</strong> that the<br />

* requested action exists in the lookup array<br />

*/<br />

if ( $_POST['token']==$_SESSION['token']<br />

&& isset($actions[$_POST['action']]) )<br />

{<br />

$use_array = $actions[$_POST['action']];<br />

$obj = new $use_array['object']($dbo);<br />

if ( TRUE === $msg=$obj->$use_array['method']() )<br />

{<br />

header($use_array['header']);<br />

exit;<br />

}<br />

else<br />

{<br />

// If an error occured, output it <strong>and</strong> end execution<br />

die ( $msg );

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

Saved successfully!

Ooh no, something went wrong!