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 meta tag provides a short description of the page?
<meta content="..."> <meta description="..."> <meta http-equiv="...">
<meta name="description" content="70-160 characters that describes the content of the page" />
Which CSS property is used to stop the wrapping effect of the "float"?
clear text-align position
#some_id {
  clear: both;
}
Click on the method which gets an array with all the elements in the document that have a specified tag name.
getElementsByName() getElementById() getElementsByTagName()
var divs = document.getElementsByTagName("div");
var nr_divs = divs.length;
alert(nr_divs);
Indicate the PHP function which returns the number of elements in array.
is_array() count() strlen()
$arr = array(7, 8, "abc", 10);
$nri = count($arr);
echo $nri;        // 4
Simple Admin Login PHP Script

Last accessed pages

  1. Linebacker Alley (541)
  2. Ben 10 Atv (452)
  3. Sport Games (6888)
  4. PHP PDO - exec (INSERT, UPDATE, DELETE) MySQL (35493)
  5. PHP MySQL - WHERE and LIKE (14802)

Popular pages this month

  1. Qwop (5907)
  2. Drag Racer V3 (4004)
  3. Bubbles3 (1740)
  4. List with All the Games (1416)
  5. Butterfly Kyodai (1385)