9 Replies - 2164 Views - Last Post: 15 September 2011 - 08:26 AM Rate Topic: -----

#1 komanche  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-July 09

php login script returns blank page

Posted 12 September 2011 - 05:20 AM

I have been working on the login page and have tried to simplify it but keep getting the same result. A blank page even with a wrong password. only time i get the expected result is when there are no values entered it returns "You must supply username / password";
the connection works fine because i have changed the link and get an error i can create records just the login returns the blank page.
here is the login form
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
	<link rel="stylesheet" type="text/css" href="stylesheet/disp.css" />

</head>

<body>
	<div id="wrapper">
    	<form action="methods/login.php" method="post">
		<ul>
        	<li><label>Username:</label><input type="text" name="username" size="10" value="<?php echo htmlentities("$username"); ?>" /></li>
            <li><label>Password:</label><input type="password" name="password" size="10" value="<?php echo htmlentities("$password"); ?>" /></li>
            <li><input type="submit" name="login" value="Log In" /></li>
            <li><input type="submit" name="join" value="Join" />
        </ul>
        </form>
      </div>
</body>
</html>



the php login script
-<?php
	/**
	** handles the login feature of the sote 
	** check username and password with variables in the database
	*/
		
		require_once("../includes/ikobe.php");
		
		if (isset($_POST['username']) &&isset($_POST['password']))
		{
			$username = $_POST['username'];
			$password = $_POST['password'];
			var_dump($username,$password);
		
			$pass = sha1($password);
				
				 
				
				if (!empty($username) &&!empty($password))
				{
					$query = "SELECT 'id' FROM 'users' WHERE username= '$username' AND password= '$pass'";
														
					if ($query_run = mysql_query($query))
					{
						$query_num_row = mysql_num_rows($query_run);
						
							if ($query_num_row==0)
							{
								echo 'Invalid username / password combination';
								die();
							}
							else if ($query_num_row==1)
							{
								echo 'ok.';
							}
						
					}
				}
				else
				{
					echo 'You must supply a username and password.';
				}
		}
		
		

?>


any help will be greatly appreciated

Is This A Good Question/Topic? 0
  • +

Replies To: php login script returns blank page

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3512
  • View blog
  • Posts: 10,136
  • Joined: 08-June 10

Re: php login script returns blank page

Posted 12 September 2011 - 05:28 AM

what does $query_num_row contain? the if() statement has an unchecked 3rd option (anything except 0/1)
Was This Post Helpful? 0
  • +
  • -

#3 Boy67  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 48
  • Joined: 28-August 08

Re: php login script returns blank page

Posted 12 September 2011 - 08:49 AM

Hmm, try this:

$query = "SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$pass'";


Boy67
Was This Post Helpful? 0
  • +
  • -

#4 Duckington  Icon User is offline

  • D.I.C Addict

Reputation: 170
  • View blog
  • Posts: 608
  • Joined: 12-October 09

Re: php login script returns blank page

Posted 12 September 2011 - 10:09 AM

I can see a few things wrong with it, though for the time being, change it to this and see what message gets displayed:

<?php
	/**
	** handles the login feature of the sote 
	** check username and password with variables in the database
	*/
		
		require_once("../includes/ikobe.php");
		
		if (isset($_POST['username']) &&isset($_POST['password']))
		{
		
		
		
			$username = $_POST['username'];
			$password = $_POST['password'];
			var_dump($username,$password);
		
			$pass = sha1($password);
				
				 
				
				if (!empty($username) &&!empty($password))
				{
				
				
					$query = "SELECT 'id' FROM 'users' WHERE username= '$username' AND password= '$pass'";
														
					if ($query_run = mysql_query($query))
					{
						$query_num_row = mysql_num_rows($query_run);
						
							if ($query_num_row==0)
							{
								echo 'Invalid username / password combination';
								die();
							}
							else if ($query_num_row==1)
							{
								echo 'ok.';
							}
						
					}
					else
					{
					 echo 'Query Not Run';
					}
					
					
					
				}
				else
				{
					echo 'You must supply a username and password.';
				}
				
				
				
				
		}
		else
		{
			echo 'Username/password not set';
      }		
		
		
		

?>



Because you had a couple of "if"s without an else, so it the statement fails, then it'll just be a blank page.

If it's still blank with that, then I would hazard a guess that it's the "require" bit.
Was This Post Helpful? 0
  • +
  • -

#5 komanche  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-July 09

Re: php login script returns blank page

Posted 13 September 2011 - 05:13 AM

Thanks alot for the input it has made a change which it now displays the error message wrong username / password each time
even with the correct password and username.
I have tried adding the connection link on the page itself and not requiring it or including it and still the same result.
any other ideas as i cant work out why i can display contents from the database table to page in the website using a simple script.
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6048
  • View blog
  • Posts: 23,473
  • Joined: 23-August 08

Re: php login script returns blank page

Posted 13 September 2011 - 05:17 AM

Show your CURRENT code! Also, if you're receiving errors, copy and paste them exactly as they appear.
Was This Post Helpful? 0
  • +
  • -

#7 komanche  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-July 09

Re: php login script returns blank page

Posted 15 September 2011 - 05:49 AM


I have tried two different solutions the first one
-<?php
	/**
	** handles the login feature of the sote 
	** check username and password with variables in the database
	*/
		
		require_once("../includes/ikobe.php");
		
		if (isset($_POST['username']) && isset($_POST['password'])) 
		{
		
		$username = $_POST['username'];
		$password = $_POST['password'];
		$pass = sha1($password);
		
		 if (!empty($username) &&!empty($password))
                {
                    $query = "SELECT 'id' FROM 'users' WHERE username= '$username' AND password= '$pass'";

                    if ($query_run = mysql_query($query))
                    {
                        $query_num_row = mysql_num_rows($query_run);
                         
                            if ($query_num_row==0)
                            {
                                echo 'Invalid username / password combination';
                                die();
                            }
                            else if ($query_num_row==1)
                            {
                                echo 'ok.';
                            }
                   }
                    else
                    {
                     echo 'Query Not Run';
                    }
                }
                else
                {
                    echo 'You must supply a username and password.';
                }
        }
        else
        {
            echo 'Username/password not set';
      }    
	
?>



Am getting "-Query Not Run"

and when i use this
-<?php
	/**
	** handles the login feature of the sote 
	** check username and password with variables in the database
	*/
		
		require_once("../includes/ikobe.php");
		
		if (isset($_POST['username']) && isset($_POST['password'])) 
		{
		
		$username = $_POST['username'];
		$password = $_POST['password'];
		$pass = sha1($password);
		
		if (!empty($username) && !empty($password))
		{
			
			$query = "SELECT id FROM users WHERE username ='$username' AND password ='$pass' LIMIT 1";
			$query_run = mysql_query($query);
			
				$query_num_row = mysql_num_rows($query_run);
				
				if (mysql_num_rows($query_run) == 0)
				{
					echo 'Invalid username / password';
					
				}
				else 
				{
					echo 'Ok';
				}
			}
			else
			{
				echo 'please fill in values for username and password';
			}
		}
		
?>



the return page displays "-Invalid username / password"
I have even tried using ` quotes on id field and users and still get the same result.
Am at wits end here where am I going wrong any help??

This post has been edited by Dormilich: 15 September 2011 - 06:19 AM
Reason for edit:: condensing code

Was This Post Helpful? 0
  • +
  • -

#8 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3512
  • View blog
  • Posts: 10,136
  • Joined: 08-June 10

Re: php login script returns blank page

Posted 15 September 2011 - 06:23 AM

View Postkomanche, on 15 September 2011 - 02:49 PM, said:

Am getting "-Query Not Run"

of course, the query is invalid.

View Postkomanche, on 15 September 2011 - 02:49 PM, said:

the return page displays "-Invalid username / password"

then your username/password hash doesn’t match. are you certain that the DB contains SHA1 hashes?
Was This Post Helpful? 0
  • +
  • -

#9 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5226
  • View blog
  • Posts: 27,000
  • Joined: 10-May 07

Re: php login script returns blank page

Posted 15 September 2011 - 07:15 AM

View Postkomanche, on 13 September 2011 - 08:13 AM, said:

Thanks alot for the input it has made a change which it now displays the error message wrong username / password each time
even with the correct password and username.

Rather than just displaying the error message, when you are troubleshooting your code you should echo out anything you can't see. That way you can see why it thinks what it is comparing is incorrect.
Was This Post Helpful? 0
  • +
  • -

#10 Duckington  Icon User is offline

  • D.I.C Addict

Reputation: 170
  • View blog
  • Posts: 608
  • Joined: 12-October 09

Re: php login script returns blank page

Posted 15 September 2011 - 08:26 AM

Do:

print_r($_POST)



And you can see what the POST values being submitted are, maybe there is something wrong with them. You could then echo out the SHA'd version of the password and check the database yourself to see if there is anything that matches.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1