I still have this simple loginscript that works pretty well with a single username. It also redirects to only 1 page.
For the site i'm working on right now, i need to have 2 different usernames each redirecting to another page. Is there any way to adjust the existing script?
PHP Code:<?php
/* secret.php
CONSTANT DECLARATIONS - DO NOT CHANGE UPPERCASE CONSTANTS.
Change lowercase values only
*/
/* Administration */
define("ADMINUSER", "admin"); /* your administration login name - modify - you make it up */
define("ADMINPASSWORD", "admin"); /* your administration password - modify - you make it up */
/* below is the webpage you will go to if your login is successful */
define("ADMINHOME", "test.php"); /* your administration page name - modify - the page you go to if the login is successful: Example: admin.php */
?>PHP Code:<?php
//adminLogin.php
//
// requires for multi applications inter-operability using same admin-Login-Only module
if(file_exists("secret.php")) { // admin-Login-Only admin user and password file
require_once("secret.php");
}
// begin SECURITY - DO NOT CHANGE!
// initialize or retrieve the current values for the login variables
$loginAttempts = !isset($_POST['loginAttempts'])?1:$_POST['loginAttempts'];
$formuser = !isset($_POST['formuser'])?NULL:$_POST['formuser'];
$formpassword = !isset($_POST['formpassword'])?NULL:$_POST['formpassword'];
if(($formuser != ADMINUSER ) || ($formpassword != ADMINPASSWORD )) {
if ($loginAttempts == 0) { /* 1 strikes and they're out */
$_POST['loginAttempts'] = 1;
include("meplog.php");
exit;
}else{
if ( $loginAttempts >= 1 ) {
header("Location: http://www.meppers.nl/index.php");
exit();
}else{
header("Location: http://www.meppers.nl/index.php");
exit();
}
}
}
/* test for valid username and password
if valid then initialize the session
register the username and password variables
and include the ADMINHOME page
*/
if (($formuser == ADMINUSER ) && ($formpassword == ADMINPASSWORD )) { // test for valid username and password
session_start();
$_SESSION['adminUser'] = ADMINUSER;
$_SESSION['adminPassword'] = ADMINPASSWORD;
$SID = session_id();
$adminHome = ADMINHOME;
header("Location: http://www.meppers.nl/".$adminHome);
exit();
}
?>PHP Code:<?php
//adminLogOut.php
//
/*
If you enable register_globals, session_unregister() should be used since session
variables are registered as global variables when session data is deserialized.
http://www.php.net/manual/en/ref.session.php
*/
session_start();
function session_clear() {
// if session exists, unregister all variables that exist and destroy session
$exists = "no";
$session_array = explode(";",session_encode());
for ($x = 0; $x < count($session_array); $x++) {
$name = substr($session_array[$x], 0, strpos($session_array[$x],"|"));
if (session_is_registered($name)) {
session_unregister('$name');
$exists = "yes";
}
}
if ($exists != "no") {
session_destroy();
}
}
session_clear();
?>and the protected pages have the following line on topPHP Code:<?php
//adminOnly.php
//
session_start();
if( (!isset($_SESSION['adminUser'])) || (!isset($_SESSION['adminPassword'])) ) {
include_once("adminLogin.php");
exit;
}
// requires for multi applications inter-operability using same admin-Login-Only module
if(file_exists("secret.php")) { // admin-Login-Only admin user and password file
require_once("secret.php");
}
/* adminOnly.php
if the session variables are not set or are incorrect values
then present the login screen
*/
if( ($_SESSION['adminUser'] != ADMINUSER) || ($_SESSION['adminPassword'] != ADMINPASSWORD) ) {
include_once("adminLogin.php");
exit;
}else{?>
<?php }?>
PHP Code:<?php require_once("adminOnly.php");?>



Reply With Quote

Thanks though!


Bookmarks