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 tag is a block element?
<div> <img> <span>
<div>Web Programming and Development</div>
Which CSS code displays the text underlined?
font-style: italic; text-decoration: underline; font-weight: 500;
h2 {
  text-decoration: underline;
}
Click on the JavaScript function that can access other function after a specified time.
insertBefore() setTimeout() querySelector()
function someFunction() { alert("CoursesWeb.net"); }
setTimeout("someFunction()", 2000);
Click on the instruction that returns the number of items of a multidimensional array in PHP.
count($array) count($array, 1) strlen()
$food = array("fruits" => array("banana", "apple"), "veggie" => array("collard", "pea"));
$nr_food = count($food, 1);
echo $nr_food;       // 6
Simple Admin Login PHP Script

Last accessed pages

  1. jQuery get() and post() (1804)
  2. Bubble Tanks 3 (20303)
  3. Read Excel file data in PHP - PhpExcelReader (39764)
  4. Working with getElementsByTagName (8420)
  5. Convert BBCode to HTML and HTML to BBCode with JavaScript (2532)

Top accessed pages

  1. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (50906)
  2. Read Excel file data in PHP - PhpExcelReader (39764)
  3. PHP-MySQL free course, online tutorials PHP MySQL code (37936)
  4. Get Attribute (ID, Class, Name, Title, Src) with jQuery (34200)
  5. PHP PDO - exec (INSERT, UPDATE, DELETE) MySQL (31686)