HTML interesse |
|
Ik gebruik op een website een login op basis van cookies, niet het meest betrouwbare volgens velen maar je moet ergens mee beginnen!
Die Login gebruik ik op meerdere pagina's met meerdere gebruikers, echter heb ik nu op 1 pagina een beperking nodig voor 3 gebruikers.
Het vervelende is dat alle ingelogde leden ook op die pagina kunnen komen nu....
Misschien dat een wat meer ervaren php' er wat op weet?
Dit is de scripting waar het over gaat:
<?
header("Pragma: ");
header("Cache-Control: ");
header("Expires: Mon, 26 Jul 1980 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
//set global variables
global $username,$password;
//header("Pragma: no-cache");
// EDIT HERE TO SUIT YOUR NEEDS
//set usernames and passwords
//only letters and numbers (no spaces) Known as can contain spaces
$uname[0] = "Ronald";
$upass[0] = "pass";
$known_as[0] = "Ronald user";
//additional users can be added
$uname[1] = "Robert";
$upass[1] = "pass";
$known_as[1] = "Robert user";
$uname[2] = "Reinier";
$upass[2] = "pass";
$known_as[2] = "Reinier user";
$uname[3] = "Julian";
$upass[3] = "Ipass";
$known_as[3] = "Julian user";
$uname[4] = "Patrick";
$upass[4] = "pass";
$known_as[4] = "Patrick user";
$uname[5] = "Angelo";
$upass[5] = "pass";
$know_as[5] = "Angelo user";
$uname[6] = "Wilco";
$upass[6] = "pass";
$known_as[6] = "Wilco user";
$uname[7] = "Hans";
$upass[7] = "pass";
$known_as[7] = "Hans user";
$uname[8] = "Hetty";
$upass[8] = "pass";
$known_as[8] = "Hetty user";
$uname[9] = "Fajar";
$upass[9] = "pass";
$known_as[9] = "Fajar user";
//the login page
$login_page = "index.php";
//where to go after login
$success_page = "1.php";
//the path to validate.php
$validate_path = "full path to validate.php";
//login failed error message
$login_err = '<div class="12pxtitel" align="center">Je User Name of Password klopt niet.</b><br><br></div>';
//no fields filled in
$empty_err = '<div class="12pxtitel" align="center"><b>Je moet inloggen met je User Name en Password.</b><br><br></div>';
//something entered that wasn't a letter or number error message
$chr_err = '<div class="12pxtitel" align="center"><b>Probeer het nog eens.</b><br><br></div>';
// DO NOT EDIT BELOW HERE
//if the form is empty and the cookie isn't set
//then display error message the return to login
if($username == "" && $password == "" && !isset($_COOKIE["this_cookie"])){
print($empty_err);
include($login_page);
exit();
}
//if the form is not empty and the cookie isn't set
//then make sure that only letters and numbers are entered
//if there are then display error message the return to login
if($username != "" || $password != "" && !isset($_COOKIE["this_cookie"])){
if (preg_match ("/[^a-zA-Z0-9]/", $username.$password)){
print($chr_err);
include($login_page);
exit();
}
}
//if the cookie isn't set
if (!isset($_COOKIE["this_cookie"]) ){
$user_count = count($uname);
$user_exists = false;
// check through all the users to see if they exist
for ($i = 0; $i <= $user_count; $i++) {
if ($uname[$i] == $username && $upass[$i] == $password){
$user_id=$i;
//$welcome_name = $known_as[$i];
$user_exists = true;
}
}
if(!$user_exists){
print ($login_err);
include($login_page);
exit();
}
//if the login is correct then set the cookie
$cookie_val=crypt($uname[$user_id]);
//set the cookie so it dies when the browser is closed
setcookie ("name", $known_as[$user_id], 0);
setcookie ("this_cookie", $cookie_val, 0);
header("Location: $success_page");
exit();
}
//if a user tries to access validate.php directly and they are logged in
if($REQUEST_URI == $validate_path){
echo "<html>\n<head>\n";
echo "<title>You are logged in</title>\n";
echo "</head>\n";
echo "<body bgcolor=\"white\">\n";
echo "You are logged in. <a href=\"".$success_page."\">Continue</a>\n";
echo "</body>\n";
echo "</html>\n";
}
?>
<? header("Expires: Mon, 26 Jul 1980 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); //set global variables //header("Pragma: no-cache"); // EDIT HERE TO SUIT YOUR NEEDS //set usernames and passwords //only letters and numbers (no spaces) Known as can contain spaces $uname[0] = "Ronald"; $upass[0] = "pass"; $known_as[0] = "Ronald user"; //additional users can be added $uname[1] = "Robert"; $upass[1] = "pass"; $known_as[1] = "Robert user"; $uname[2] = "Reinier"; $upass[2] = "pass"; $known_as[2] = "Reinier user"; $uname[3] = "Julian"; $upass[3] = "Ipass"; $known_as[3] = "Julian user"; $uname[4] = "Patrick"; $upass[4] = "pass"; $known_as[4] = "Patrick user"; $uname[5] = "Angelo"; $upass[5] = "pass"; $know_as[5] = "Angelo user"; $uname[6] = "Wilco"; $upass[6] = "pass"; $known_as[6] = "Wilco user"; $uname[7] = "Hans"; $upass[7] = "pass"; $known_as[7] = "Hans user"; $uname[8] = "Hetty"; $upass[8] = "pass"; $known_as[8] = "Hetty user"; $uname[9] = "Fajar"; $upass[9] = "pass"; $known_as[9] = "Fajar user"; //the login page $login_page = "index.php"; //where to go after login $success_page = "1.php"; //the path to validate.php $validate_path = "full path to validate.php"; //login failed error message $login_err = '<div class="12pxtitel" align="center">Je User Name of Password klopt niet.</b><br><br></div>'; //no fields filled in $empty_err = '<div class="12pxtitel" align="center"><b>Je moet inloggen met je User Name en Password.</b><br><br></div>'; //something entered that wasn't a letter or number error message $chr_err = '<div class="12pxtitel" align="center"><b>Probeer het nog eens.</b><br><br></div>'; // DO NOT EDIT BELOW HERE //if the form is empty and the cookie isn't set //then display error message the return to login if($username == "" && $password == "" && !isset($_COOKIE["this_cookie"])){ include($login_page); } //if the form is not empty and the cookie isn't set //then make sure that only letters and numbers are entered //if there are then display error message the return to login if($username != "" || $password != "" && !isset($_COOKIE["this_cookie"])){ if (preg_match ("/[^a-zA-Z0-9]/", $username.$password)){ include($login_page); } } //if the cookie isn't set if (!isset($_COOKIE["this_cookie"]) ){ $user_count = count($uname); $user_exists = false; // check through all the users to see if they exist for ($i = 0; $i <= $user_count; $i++) { if ($uname[$i] == $username && $upass[$i] == $password){ $user_id=$i; //$welcome_name = $known_as[$i]; $user_exists = true; } } if(!$user_exists){ include($login_page); } //if the login is correct then set the cookie $cookie_val=crypt($uname[$user_id]); //set the cookie so it dies when the browser is closed header("Location: $success_page"); } //if a user tries to access validate.php directly and they are logged in if($REQUEST_URI == $validate_path){ echo "<title>You are logged in</title>\n"; echo "<body bgcolor=\"white\">\n"; echo "You are logged in. <a href=\"".$success_page."\">Continue</a>\n"; } ?>
|