pass protected
- Started
- Last post
- 5 Responses
- kodap
I need to protect only one page (html content) with a password and user, how do I do that -
it's so simple... I can't find a single php sample for that.
btw: my coding skills are quite low.
but I think it's damn simple- just 2 or 3 lines of code.....
(just a single user and pass user)
thx
- sparker0
well, not one or two lines of code, but http://hotscripts.com/ should have countless scripts to choose from.
php, perl, python...etc...all will work, but it will be more than a few lines of code.
- jevad0
.htaccess my friend...
- JamesEngage0
doa search on a php thing called phpaccess.php... lets you add users etc.
- rasko40
check that your host doesn't have an option in your control panel, could save a bit of work.
- unfittoprint0
w/ MySQL [> 1 user]?
I use [secure method]:
[?php
foreach ($HTTP_POST_VARS as $key => $value) {
$$key = $value;
}function auth($username, $password) {
$crypt = md5($password);
$query = "SELECT userID FROM users WHERE username = '$username' AND password = '$crypt'";// Execute the query
$result = mysql_query($query);// If we found a match...
if (mysql_num_rows($result) == 1) {
// Extract user ID from the results
$user = @mysql_fetch_array($result);
$userID = $user['userID'];
} else {
// Otherwise set username to -1
$userID = -1;
}
// Return user ID
return $userID;
}//____________________
$userID = auth($username, $password);
// If authorisation failed...
if ($userID == -1) {
fail("UTILIZADOR / PASSWORD INVÁLIDOS
Clique aqui para tentar de novo");
} else {
session_start(); $_SESSION['username'] = $username;
$_SESSION['password'] = $password;
$_SESSION['userID'] = $userID;
//ir para a página loggedin
header("Location: loggedin.php");
}
}?]