Jump to content

Login page for secure directory


arifsor

Recommended Posts

You can use PHP most definitely. Here's one I just made. I haven't tested it, but if any errors occur you could probably pick them out.

 

On all pages add this:

<?php
if(!isset($_SESSION[logged])){
header("Location: login.php");
}else {
//content
}
?>

//this will be login.php

<?php
session_start();
if(!isset($_SESSION[logged])){
if(!isset($_POST[action])){
echo "<table border=0 cellspacing=3 cellpadding=2>\n";
echo "<tr><td colspan=2 align=right><h3>Login</h3></td></tr>\n";
echo "<form name=login method=post action=login.php>\n";
echo "<tr><td>Username:</td><td><input type=text name=username value=''></td></tr>\n";
echo "<tr><td>Password:</td><td><input type=password name=password></td></tr>\n";
echo "<tr><td colspan=2 align=right><input type=hidden name=action value=login><input type=submit value='Login!'></td></tr>\n";
echo "</form></table>\n";
}else {
	if($_POST[action] == login){
	$username = "setyourusernamehere";
	$password = "setyourpasswordhere";
	$un = $_POST[username];
	$pw = $_POST[password];
		if(isset($un) && isset($pw)){
			if($un == $username && $pw == $password){
			$_SESSION[logged] = "yes";
			header("Location: index.php");
			}else {
			echo "The username and password combination was incorrect!";
			}
		}else {
		echo "You did not supply either a username or a password!";
		}
	}else {
	echo "Error in the file!";
	}
}
}else {
header("Location: index.php");
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.