<?php
session_start();
$name[] = "Devillman"; $pass[] = "Devillman";
$name[] = "admin"; $pass[] = "admin";
$name[] = "test"; $pass[] = "test";
//добави колкото искаш
function loginform(){ //формата, която потребителите виждат ако не са се логнали
echo '<fieldset style="padding: 2">';
echo '<legend>Login</legend>';
echo '<form method=post action="?">';
echo 'Name: <input type=text name=username value="' . $_POST[username] . '">'; //името
echo '<br>';
echo 'Pass: <input type=password name=pass>'; //паролата
echo '<br>';
echo '<input type=submit name="s1" value="Login">';
echo '</form>';
echo '</fieldset>';
}
if($_GET['action'] == "logout"){
$_SESSION['loggedin'] = false;
$_SESSION['username'] = "";
}
if($_SESSION['loggedin'] == false){
if(!$_POST['s1']){
loginform();
}else{
$tmpname = $_POST['username']; #the username the user has submitted
$tmppass = $_POST['pass']; #the password the user has submitted
$t = count($name); #count the total users
$i = 0;
while($i <= $t){
if($tmpname == $name[$i] && $tmppass == $pass[$i]){
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $name[$i];
header('Location: ?'); #reload the page
}
$i++;
}
echo "invalid name and password "; //Ако е сгрешено името или паролата
loginform(); #show the form
}
die;
}
?>
Welcome <?php echo $_SESSION['username']; ?>. Testova stranica - ti se logna uspeshno<BR>
<a href="http://web-tourist.net">Poseti Web-Tourist</a>
<br>
<a href="?action=logout">Logout</a>