Jump to content


Photo

Unwanted Output


  • Please log in to reply
4 replies to this topic

#1 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 17 September 2006 - 02:50 AM

Hello, I just cant seem to get the output i wanted i change 2 or 3 lines of code and cant get it to work:

I want it to say login sucessful instead of error.

login_form.php:
<?php
// initialize a session
session_start();
?>
<html>
<head></head>
<body>

<?php
if (!isset($_SESSION['user']) && !isset($_COOKIE['user']) && !isset($_POST['pass'])) {
    // if no data, print the form
?>
    <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
       Username:<input type="text" name="user"><br>
	   Password:<input type="password" name="pass"><br>
        <input type="submit" name="submit">
    </form>
<?php
}
if (!isset($_SESSION['user']) && !isset($_COOKIE['user']) && isset($_POST['pass'])) {

	include('connect.php');
    // if a session does not exist but the form has been submitted
    // check to see if the form has all required values
    // create a new session
	$user = empty($_POST['user']) ? die ("Please Enter A Username") : mysql_escape_string($_POST['user']);
	$pass = empty($_POST['pass']) ? die ("Please Enter A Password") : mysql_escape_string($_POST['pass']);
	$sql = "SELECT * FROM users WHERE user='$user' AND pass='$pass'";
	$result = mysql_query($sql);
	$count=mysql_num_rows($result);
	
	if($count==1){
		
		$_SESSION['user'] = $user;
		$_SESSION['pass'] = $pass;	
		?>
		
		<meta http-equiv="refresh" content="0;url=login_sucess.php">;

		<?php	
	}
		
	if ($count == 0) {
		
		echo "Username or password are incorrect";

		}	
	
}
if (isset($_COOKIE['user'])) {
echo "You are already logged in";
}
?>
</body>
</html>

login_sucess.php:
<?php
session_start();
//if (isset($_SESSION['userinfo']{
//$pass = $_SESSION['pass'];
//setcookie('pass', $pass, time()+36000*24*365);
$user = $_SESSION['user'];
setcookie('user', $user, time()+36000*24*365);
session_destroy();
//}
?>
<htmL>

<head>

</head>

<body>

<?php

if (isset($_COOKIE['user'])) {
echo "Login Complete, Welcome $user";
}

if (!isset($_SESSION['user'])) {
?>
		
<meta http-equiv="refresh" content="0;url=login_form.php">;

<?php	
}

if (!isset($_COOKIE['user'])) {
echo "Error";
}
?>

</body>
</html>

Cheers, Daniel

#2 markbett

markbett
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 17 September 2006 - 02:56 AM

does it actually say error?? or does it say  "Username or password are incorrect";


#3 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 17 September 2006 - 02:58 AM

With login_sucessful.php line 34 where it says echo "error".

Thats what i always get.

- Cheers, Daniel

#4 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 17 September 2006 - 03:06 AM

Please help.

- Cheers, Daniel

#5 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 17 September 2006 - 03:51 AM

Thanks, Daniel





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users