Login script problem

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

User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

<?php
<? session_start();
   include('inc/connect.php');
			
			if ($_SESSION['auth'] != 'authed') 
			{ 
			$login='1';
			include ('form.php');
			}
			if (isset($_POST['submit']))
			{
			$email = $_POST['email'];
			$password = $_POST['password'];

			$result = @mysql_query("SELECT * FROM user WHERE email='$email' && password='$password'") or die(mysql_error()); 
			
			if(!mysql_num_rows($result))
			{ 
			die('Invalid username and/or password'); 
			}else{
			$row = mysql_fetch_array($result);
			$userlevel = $row['userlevel'];
			$_SESSION['auth'] = 'authed';
			$_SESSION['userlvl'] = $userlevel;

			if ($_SESSION['userlvl']=='admin')
			{
			header('Location: adminpanel.php');
			exit();
			}elseif ($_SESSION['userlvl']=='customer'){
			header('Location: customerpanel.php');
			exit();
			}
			}
			}

?>

?>
Is outputting the header already sent msg... there is no output being outputted when there are no errors...
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

What's the exact error message for the header? And what is the line that it says output was started on?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Warning: Cannot modify header information - headers already sent by (output started at /home/jcart/public_html/active/form.php:3) in /home/jcart/public_html/active/login.php on line 30
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

So it's coming from include ('form.php'); which i presume includes the login form.
The code flow/logic should really be...
if not isset submit
then include the form and exit
else
if authenticated then redirect
else
show the login form (or reditect so it redisplays it)

Putting the form before the authentication will cause output, so it needs to only be shown if submit hasn't been pressed or authentication failed.
Hope that makes sense. If not let us knwo and i'll amend your code ;)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

thanks alot mark :)
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

Phenom wrote:1 more problem... how do i send a header in the middle of a script without getitng the header already sent error... :S
I know your not new here...
and it is frowned upon when you ask questions that have been done a million times

viewtopic.php?t=1157
check that out...
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I know that I couldn't have output... but i didn't see where the output was coming from giving me the error.... ty gg bye.

while ($illusionist != 'productive'){

slap illusionist with a trout

}
Post Reply