PDA

View Full Version : Password Protection


Abd
10-02-2002, 06:49 PM
Hi All,

please does any one have a code on password protection that checks username and password in a Database before displaying the required web page

Abd

arik00
10-03-2002, 05:22 AM
in my administration portion of every project:


<?php
if(isset($_POST['submit'])) { // true if form has been submitted
session_start();
include("./System/backend.inc");
$password = base64_encode($password);
$q = "SELECT AdminID FROM admins WHERE Username='$username' AND Password='$password' ";
$security = db_query($q);

if(mysql_num_rows($security)) {
list($sequrity_id) = mysql_fetch_row($security);

$sess_security_id = $security_id;
session_register('sess_security_id');
header("location: ./entry_page.php");
}

// authorization not successful show form again...
}

?>
<html>
<head>
<link REL="StyleSheet" HREF="../style.css" TYPE="text/css">
<title>Authorization.</title>
</head>
<body>
<form action="<? echo $PHP_SELF; ?>" method="post">
<font class="content">Username : <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="hidden" name="submit" value="1">
<input type="submit" value="Login">
</form></html>


and execute this function in every page


function check_id() {
session_start();
if(!session_is_registered('sess_security_id')) {
header("location: ./index.php");
}
}


you should first include it, and then execute it.

Arik
:rolleyes: