<?php
session_start();
$name[] = "Chris"; $pass[] = "123456";
$name[] = "Test"; $pass[] = "weewee";
$name[] = "blah"; $pass[] = "moo";
#create an array of usernames and passwords
#add as many as you want
function loginform(){ #this is the form the user sees if they are not logged in
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>';
}
#used for the logout link, changes the session 'loggedin' = false if ?action=logout
if($_GET['action'] == "logout"){
$_SESSION['loggedin'] = false;
$_SESSION['username'] = "";
}
if($_SESSION['loggedin'] == false){ #checks if the user isnt logged in
if(!$_POST['s1']){ #checks if the form has been submitted, if not show it
loginform();
}else{
#username check
$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;
#create a loop to go through each username/password and compare it with the name pass which was submitted
while($i <= $t){
if($tmpname == $name[$i] && $tmppass == $pass[$i]){
#if the name/pass submitted matches any of the username and passwords set the session 'loggedin' = true
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $name[$i];
header('Location: ?'); #reload the page
}
$i++;
}
echo "invalid name and password :o"; #show an error message if the user enters an incorrect name/pass
loginform(); #show the form
}
die;
}
?>
Welcome <?php echo $_SESSION['username']; ?>. anything put here is only visible to users who are logged in
<br>
<a href="?action=logout">Logout</a>
<?php
session_start();
if (($_SESSION[loggedin])== true){
echo "You are logged in";}
else {header('Location: ../login.php');
}
?>
<?php
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $name[$i];
header('Location: /download1/index.php'); #reload the page
?>
<?php
include 'config.php';
?>
<?php
while($i <= $t){
if($tmpname !== "" || $tmppass !== ""){
if($tmpname == $name[$i] && $tmppass == $pass[$i]){
#if the name/pass submitted matches any of the username and passwords set the session 'loggedin' = true
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $name[$i];
header('Location: ?'); #reload the page
}
}
$i++;
}
?>
<?php
session_start();
$name[] = "Chris"; $pass[] = "123456";
$name[] = "Test"; $pass[] = "weewee";
$name[] = "blah"; $pass[] = "moo";
#create an array of usernames and passwords
#add as many as you want
function loginform(){ #this is the form the user sees if they are not logged in
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>';
}
#used for the logout link, changes the session 'loggedin' = false if ?action=logout
if($_GET['action'] == "logout"){
$_SESSION['loggedin'] = false;
$_SESSION['username'] = "";
}
if($_SESSION['loggedin'] == false){ #checks if the user isnt logged in
if(!$_POST['s1']){ #checks if the form has been submitted, if not show it
loginform();
}else{
#username check
$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;
#create a loop to go through each username/password and compare it with the name pass which was submitted
while($i <= $t){
if($tmpname !== "" || $tmppass !== ""){
if($tmpname == $name[$i] && $tmppass == $pass[$i]){
#if the name/pass submitted matches any of the username and passwords set the session 'loggedin' = true
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $name[$i];
header('Location: ?'); #reload the page
}
}
$i++;
}
echo "invalid name and password :o"; #show an error message if the user enters an incorrect name/pass
loginform(); #show the form
}
die;
}
?>
Welcome <?php echo $_SESSION['username']; ?>. anything put here is only visible to users who are logged in
<br>
<a href="?action=logout">Logout</a>
<?php
session_start();
$name[] = "admin"; $pass[] = "blah";
$name[] = "blah"; $pass[] = "blah";
$name[] = "blah"; $pass[] = "blah";
$name[] = "blah"; $pass[] = "blah";
#create an array of usernames and passwords
#add as many as you want
#used for the logout link, changes the session 'loggedin' = false if ?action=logout
if($_GET['action'] == "logout"){
$_SESSION['loggedin'] = false;
$_SESSION['username'] = "";
}
if (($_SESSION[loggedin])== false){
if(!$_POST['s1']){
header('Location: ../admin-login.php');
}else{
#username check
$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;
#create a loop to go through each username/password and compare it with the name pass which was submitted
while($i <= $t){
if($tmpname !== "" || $tmppass !== ""){
if($tmpname == $name[$i] && $tmppass == $pass[$i]){
#if the name/pass submitted matches any of the username and passwords set the session 'loggedin' = true
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $name[$i];
header('Location: ?'); #reload the page
}
}
$i++;
}
echo "Invalid Username or Password 0.o";#show an error message if the user enters an incorrect name/pass
}
die;
}
?>
Welcome <?php echo $_SESSION['username']; ?>.<br>
<a href="?action=logout">Logout</a><br><br>