This is an Admin Login script made with PHP.
It is useful if you want to implement in your site a simple admin login system, without database.
The users are added manually by the Administrator, in the php code of this script. You can add multiple admin-user accounts with a Rank number to each one, so, then you can display content for loged Admin in your site according to its rank.

• To download the script, click on this link: Download Admin Login Script (4 KB).

Code of the script

Click on the code to select it.
<?php
//Simple Admin Login PHP Script - From: http://coursesweb.net/
session_start();

//Here add users that can login as admin
$admins =[
 ['user'=>'Admin', 'pass'=>'password', 'rank'=>9],
 ['user'=>'admin2', 'pass'=>'pass', 'rank'=>7],
 ['user'=>'admin-3', 'pass'=>'passx', 'rank'=>4]
];

//form to log-in
$re_cnt ='<form action="'. basename($_SERVER['PHP_SELF']) .'" method="post" id="login">
 <label>Name: <input type="text" name="user" id="user" /></label>
 <label>Password: <input type="password" name="pass" id="pass" /></label>
 <input type="submit" value="Send" id="submit" />
</form>';

//to logout
if(isset($_GET['lgo']) && $_GET['lgo']=='logout'){
  if(isset($_SESSION['adminlog'])) unset($_SESSION['adminlog']);
  if(isset($_SESSION['adminrank'])) unset($_SESSION['adminrank']);
  if(isset($_SESSION['adminix'])) unset($_SESSION['adminix']);
  $re_cnt ='<h4>Logged out</h4>' .$re_cnt;
}
else if(isset($_POST['user']) && isset($_POST['pass'])){ //form data sent to log-in
  //check if correct login data
  $err ='<h4>Incorrect User name or Password</h4>';
  $nradm = count($admins);
  for($i=0; $i<$nradm; $i++){
    if($_POST['user']==$admins[$i]['user'] && $_POST['pass']==$admins[$i]['pass']){
      //set session with admin
      $_SESSION['adminlog'] = $admins[$i]['user'];
      $_SESSION['adminrank'] = $admins[$i]['rank'];
      $_SESSION['adminix'] = $i;
      $err ='';
      break;
    }
  }

  //if error, add it to output
  if($err!='') $re_cnt = $err .$re_cnt;
}

//admin loged
if(isset($_SESSION['adminlog']) && isset($_SESSION['adminrank'])){
  //Here you can set /include additional content for logged admin

  $re_cnt ='<h4>Logged</h4>User: '. $_SESSION['adminlog'] .'<br>Rank: '. $_SESSION['adminrank'] .'<br><br><a href="'. basename($_SERVER['PHP_SELF']) .'?lgo=logout" title="Log-Out" id="logout">Log-Out</a>';
}
?><!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Admin Login System</title>
<meta name="description" content="Simple Admin Login System with php, without database. From: http://coursesweb.net/" />
<meta name="author" content="MarPlo" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
body {text-align:center;margin:0 1%; padding:0;}
h1 {
font-size:22px;
margin:10px auto 18px auto;
text-decoration:underline;
}
#content {
margin:0 auto 18px auto;
}
#logout {
display:block;
font-style:oblique;
font-size:17px;
font-weight:700;
margin:0;
}

#login {
position:relative;
width:13em;
margin:10% auto 2em auto;
background:#fefefe;
padding:1em;
border:2px solid #bbb;
font-size:1.2em;
font-weight:700;
}
#login label {
display:block;
margin:.2em 1px;
text-align:left;
}
#login #user, #login #pass {
width:10.7em;
background:#ff1;
padding:.1em;
font-style:oblique;
}
#login #user:focus, #login #pass:focus {
background:#d1e0fb;
}
#login #user {
margin-left:2.2em;
}
#login #submit {
display:block;
margin:1em auto .5em auto;
}
#footer {
margin:0 auto;
}
#cwb {
display:block;
font-style:oblique;
margin:11% auto 15px auto;
}
</style>
</head>
<body>
<h1>Admin Login System</h1>
<div id="content">
<?php echo $re_cnt; ?>
</div>
<a href="/" title="CoursesWeb" title="Home Page">Home Page</a>
<footer id="footer">
<a href="http://coursesweb.net/" title="CoursesWeb" id="cwb">CoursesWeb.net</a>
</footer>
</body>
</html>

Usage

  1. Copy the code of the script and save it into a "admin.php" file; or Download the script from the link above.
  2. In the "admin.php" file set Admin accounts, in the $admins array; then copy the file on your server.
  3. To login as Admin, just access the "admin.php" page in your server.
  4. The script stores the Username and Rank of the logged Admin in the sessions: $_SESSION['adminlog'] and $_SESSION['adminrank'].
    To display different content in your site according to the logged Admin and its Rank, check and use those session variables, like in this example (see also the "test.php" file, in the archive with the script).
    <?php
    //Start session
    session_start();
    
    //check if admin loged
    if(isset($_SESSION['adminlog']) && isset($_SESSION['adminrank'])){
      //set content according to admin rank
      if($_SESSION['adminrank'] >=9){
        $content ='Content for Admin with Rank 9+';
      }
      else if($_SESSION['adminrank'] >=5){
        $content ='Content for Admin with Rank 5+';
      }
      else {
        $content ='Content for logged Admin with rank lower than 5';
      }
    }
    else {
      $content ='Content for no logged Admin.';
    }
    
    echo $content;
    
  5. To Log-Out, just access a link that opens this URL: "admin.php?lgo=logout".
    <a href="admin.php?lgo=logout" title="Log-Out">Log-Out</a>
    

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which attribute is used in <a> tag for the address of the link?
src href rel
<a href="http://coursesweb.net/" title="CoursesWeb.net">CoursesWeb.net</a>
Which CSS property sets the type of the text font?
font-family text-decoration font-size
h2 {
  font-family:"Calibri",sans-serif;
}
What instruction selects all the <div> tags with class="cls"?
querySelector("div.cls") getElementsByTagName("div") querySelectorAll("div.cls")
var elm_list = document.querySelectorAll("div.cls");
var nr_elms = elm_list.length;       // number of selected items
alert(nr_elms);
Indicate the function that can be used to get the sum of values in an array.
array_sum() array_diff() array_shift()
$arr = array(1, 2, 3, 4);
$arr_sum = array_sum($arr);
echo $arr_sum;       // 10
Simple Admin Login PHP Script

Last accessed pages

  1. Snowboard Challenge (141)
  2. Sport Games (3989)
  3. Escape Games (5818)
  4. Bubbles3 (25700)
  5. The Rise Of Atlantis (5166)

Popular pages this month

  1. Qwop (4763)
  2. Bubbles3 (4403)
  3. Butterfly Kyodai (3133)
  4. Zuma Deluxe (2903)
  5. Backgammon (1486)