View Single Post
Old 04-16-07, 04:42 AM   #6
t3hl33td4rg0n
Dethklok Returns!
 
t3hl33td4rg0n's Avatar
 
Join Date: Dec 2004
Location: Kent, OH
Posts: 2,142
Send a message via AIM to t3hl33td4rg0n Send a message via MSN to t3hl33td4rg0n Send a message via Yahoo to t3hl33td4rg0n
Default Re: Need a non-functional PHP login box

Well, I dont know if this will work since I dont have my server, but here you go

This will assume you have MySQL table for users and passwords are stored with MD5 checksums.

Code:
<?php
// This goes in the login (main) page. Tailor the variables as needed

$dbserv	= 'localhost';
$dbuser	= 'dbuser';
$dbpass	= '***********';
$utbl	= 'users';

$LoginSuccess 	= './admin.php';
$LoginFail 		= './index.php';

// Assume Table of type:   UID  |  USER  |  PASS [MD5]  |  LASTLOGIN

session_start();

mysql_connect($dbserv, $dbuser, $dbpass) or die(E_USER_ERROR);

if($_POST['username']) {
	$s = 'SELECT * FROM `'.$utbl.'` WHERE `user` = `'.$_POST['username'].'` AND `pass` = `'.md5($_POST['password']).'`';
	$q = mysql_query($s) or die(mysql_error());
	if (mysql_num_rows($q) > 0) {
		$Auth = true;
		session_register($Auth);
		header("Location: ./admin.php");
	} else {
		$Auth = false;
		header("Location: ./index.php");
	}
}
?>

<html>
<!-- THIS IS THE LOGIN PAGE -->
<head>
	
</head>
<body>
	<?php if($Auth = false) { echo '<b>Username or password did not match, please try again...</b>'; } ?>
	This is the login page, place a form with POST method using a text field and password field named "Username" and "Password" respectively.	
</body>
</html>


-----------------------------------------------------------------------------------------------


<?php
// This goes in any page that is restricted to only logged in users

session_start();

if ($_SESSION['Auth'] = true) { ?>
<html>
<head>

</head>
<body>

</body>
</html>
<? } else { 
	echo "This page is restricted. Please login properly.";
}
?>
__________________


Intel QX9650 @ 3.83GHzXFX 780ieVGA GTX 560Ti8GB GSkill DDR800Creative Sound Blaster X-Fi Titanium PCI-ESeagate 1.5TB . 4x Samsung 2TB

Quote:
Originally Posted by MowTin View Post
....it's so clear how government makes things worse not better...
t3hl33td4rg0n is offline   Reply With Quote