Why Won't This Login Script Work?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
steves
Forum Newbie
Posts: 22
Joined: Wed Feb 22, 2006 9:04 am

Why Won't This Login Script Work?

Post by steves »

I'll send you a cookie if you can tell me...

Code: Select all

<?php session_start(); ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<title>Untitled</title>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">

<?php
ob_start();

if (isset($_GET['action']) && $_GET['action'] == 'submitted') {

		$_SESSION['employee'] = $_GET['this_employee'];
		$_SESSION['password']  = $_GET['password'];
		header("Location: do_what.php");
		
} else {
			
		mysql_connect( 'localhost','root','password' )
			or die( "error connecting to database to get employee list" . mysql_error() );
		mysql_select_db( 'pmg_finance' )
			or die( "could not select pmg_finance" . mysql_error() );

		echo "<form action=".$_SERVER['PHP_SELF']." method=\"GET\" />";
		$employee_query = "SELECT full_name from employees order by full_name";
		$employee_result = mysql_query( $employee_query );

		echo "<select name=\"employee_select\" size=\"1\">";
		echo "<option disabled=\"true\" value=\"\"><br>";
	
			while ($employee_fetch = mysql_fetch_object( $employee_result ))
		
			{$this_employee = $employee_fetch -> full_name ;
			echo "<option>".$this_employee."<br>";
			}

		echo "</select>";
		mysql_close();
		}
ob_end_flush();		
?>

<input type="password" name="password" />
<input type="hidden" name="action" value="submitted" />
<input type="submit" name="submit" value="Go Do It" />
</td>
</form>

</body>
</html>
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

It should be 'employee_select' not 'this_employee' in $_GET.

Code: Select all

$_SESSION['employee'] = $_GET['this_employee'];
I like chocolate chip. :D
steves
Forum Newbie
Posts: 22
Joined: Wed Feb 22, 2006 9:04 am

Post by steves »

Good catch! Unfortunately, the real problem with the script has to do with headers, and I just can't seem to find it.

I would have eventually noticed a problem with the employee_select thing if not for the headers issue, so thanks for saving me some aggravation there.
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Move ob_start() up before session_start().

Lot of work for a cookie!? :?
steves
Forum Newbie
Posts: 22
Joined: Wed Feb 22, 2006 9:04 am

Post by steves »

You're right. I said I'd send a cookie:

Name: PHPSESSID
Content: 4136fgc3gmbjhnkdessq34jm14
Host: mymac.local
Path: /
Send For: Any type of connection
Expires: at end of session
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Expires: at end of session
Hmm ... cookies never last that long around me especially chocolate chip. :D
Post Reply