Location: PHPKode > scripts > Alternate Login > alternate_login/login.php
<?php 

# COPYRIGHT
# Alternate Login © 2012 Scott Connell - All Rights Reserved.
# Source and latest version: http://scottconnell.orgfree.com
# Release Date: 2012/09/17
##########################################################
# This program is free software; you can redistribute it and/or modify it under the
# terms of the GNUv2 General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later version.
##########################################################
# SET VARIABLES #################################
# Change your password. Very important!

$admin_password = "admin"; 

# If you are running more than one application of this software,
# change the $cookie_name variable to a unique name. Otherwise,
# all of your applications will use the same cookie to login.

$cookie_name = "ALTLOGIN";

# Change the header path, and footer path,
# to your full directory path if necessary.
# Header and footer used only for login.

$header_path = "header.php";
$footer_path = "footer.php";

# There are three $title variables below, that display the login state
# through header.php, you can change them to fit your purpose.
# See first line of index.php for how to implement.
# END SETTING VARIABLES #################

function printForm()
{
$action = $_SERVER["PHP_SELF"];

print <<<ENDHTM

<form action="$action" method="post">
<p><input type="password" name="pass" value=""/> <input type="submit" value="Submit"/></p>
</form>

ENDHTM;
}

if(isset($_POST['pass']))
{
	if(strtolower($_POST['pass']) == $admin_password)
	{
	setcookie($cookie_name, md5($admin_password), time()+(60*60*24*30), "/"); // 30 days
	}
	else
	{
	$title = "Wrong Password - Please Try Again"; // Title displayed if wrong password given.
	include_once($header_path);
	printForm();
	exit(include_once($footer_path));
	}
}
else if($_SERVER['QUERY_STRING'] == "logout")
{
setcookie($cookie_name, md5($admin_password), time()-(60*60*24*30), "/"); // -30 days
$title = "Logged Out - You are now logged out of this page"; // Title displayed after logout.
include_once($header_path);
printForm();
exit(include_once($footer_path));
}
else if(!isset($_COOKIE[$cookie_name]))
{
$title = "Alternate Login - Uses just one line of code to password protect any page"; // Title displayed if not logged in.
include_once($header_path);
printForm();
exit(include_once($footer_path));
}

?>


Return current item: Alternate Login