Jump to content

[SOLVED] Need a simple user login script...


tmallen

Recommended Posts

I want a simple user login page/script that does not run over a DB. The main reason for this is to ease deployment and because security is not a huge deal for the data being protected. Here's what I'm trying now. It isn't working.

 

The form at login.php:

<form action="../scripts/login.php" method="post">
<fieldset>
	<label>Username: <span class="alert">*</span></label><input type="text" name="username" />
	<label>Password: <span class="alert">*</span></label><input type="password" name="password" />
	<input type="submit" value="Login" class="submit clear" />
	<div class="clear"></div>
</fieldset>
</form>

 

The script at ../scripts/login.php:

<?php

$username	= $_REQUEST['username'];
$password	= $_REQUEST['password'];

session_start();
$_SESSION['uid']	= $username;
$_SESSION['pass']	= $password;

header("Location: The admin homepage");

?>

 

Part of includes/header.php to check for access:

session_start();

if ($admin) {
if ($_SESSION['uid']!='admin' || $_SESSION['pass']!='adminpw') {
	echo("Permission denied for $username at $password\n");

}
}

 

And at the top of a sample admin page:

<?php
$title	= 'Downloads';
$admin	= TRUE;
include '../includes/header.php';
?>

Right now, permission is not being denied in any way to false logins, and at the top of the page I get "Permission denied for at".

 

So basically, it sets two session variables (I have no prior session experience) based on form input, and checks these variables at every $admin page. I know I'm doing many, many things wrong. Please point them out, but be gentle :^)

Link to comment
Share on other sites

just one thing

 

if ($_SESSION['uid']!='admin' || $_SESSION['pass']!='adminpw') {
	echo("Permission denied for $username at $password\n");

}

should be

 

if ($_SESSION['uid']!='admin' || $_SESSION['pass']!='adminpw') {
	echo("Permission denied for $username\n");
                          exit;

}

 

one more tip

avoid displaying any passwords on screen

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.