13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

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

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

706 Chapter 30 Building a Mailing List Manager<br />

not log you in with that email address<br />

<strong>and</strong> password.";<br />

}<br />

}<br />

if($action == 'log-out') {<br />

unset($action);<br />

$_SESSION=array();<br />

session_destroy();<br />

}<br />

As you can see, you first try to log the user in by using the login() function from the<br />

user_auth_fns.php library.This function is slightly different from the login functions<br />

used elsewhere, so let’s look at it more closely.The code for this function is shown in<br />

Listing 30.5.<br />

Listing 30.5 login()Function from user_auth_fns.php—This Function Checks a<br />

User’s Login Details<br />

function login($email, $password) {<br />

// check username <strong>and</strong> password with db<br />

// if yes, return login type<br />

// else return false<br />

// connect to db<br />

$conn = db_connect();<br />

if (!$conn) {<br />

return 0;<br />

}<br />

$query = "select admin from subscribers<br />

where email='".$email."'<br />

<strong>and</strong> password = sha1('".$password."')";<br />

$result = $conn->query($query);<br />

if (!$result) {<br />

return false;<br />

}<br />

if ($result->num_rowsfetch_array();<br />

if($row[0] == 1) {<br />

return 'admin';

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

Saved successfully!

Ooh no, something went wrong!