auth.php is just an example name for the file that holds your function or code block that is used to verify users.
require('auth.php'); will import the file and script into the current page
and auth.php will be something on the lines of
PHP Code:
<?php
//intialize variables
$user = "";
$password = "";
if (isset($_POST['submit']))
{
$user = $_POST['username'];
$pass = $_POST['password'];
// sql statement
$query = "SELECT user, password FROM users WHERE users = " . $user . "";
// $dbc stands for your database connection
$result = @mysql_query($query, $dbc);
// if there was no result, the user name was incorrect ( as long as your database connection is right
if(!$result) {
$error = 'your user name was incorrect';
}else {
while($row = mysql_fetch_array(MYSQL_BOTH, $result) {
$pwMatch = $row['password'];
$userMatch = $row['user'];
} // end while
}// end 2nd if
// if the hashed passwords match
if (md5($password) == $pwmatch) {
//then user log in is set true
$_SESSION['loggedIn'] = true;
}else {
// if the statement was false, give an error
$error = 'your password was incorrect, try again';
}// end 3rd if
}// end main if
?>
i would have more error handling and things like testing string length, but you get the idea
its where your log in script is located. rather than typing it on every page, just include or require it.
(just make sure that you have session_start(); at the top of every page before everything else)
so
PHP Code:
<?php
session_start();
require_once('auth.php'); # or where ever you file is, ie. includes/auth.php
?>
however if the file is not found, require_once will kill the script's exection unlike include_once()
Bookmarks