Solved

blank screen after php auth script

Posted on 2012-03-26
12
266 Views
Last Modified: 2012-06-20
Guys,

For some reason I cant see the issue here, can anyone see with a fresh pair of eyes why i am getting a blank load screen.

<?php
include_once 'connect.php';
session_start();

if (isset($_POST['submit']))
{
  $email=$_POST['email'];
  $password=$_POST['password'];
  $email=strip_tags($email);
  $password=strip_tags($password);
  $password=md5($password);

  $query = "SELECT * from users where email='$email' and password='$password'";
  $result = mysql_query($query) or die ("could not access users database");
  $result2 = mysql_fetch_array($result);
  if ($result2)
   {
     $_SESSION['id']=$id;

     echo "Logged In <br>";
     echo "<a href='members.php'>Continue</a>";
     exit;
  }
  else
  {
  echo "Wrong Email or Password. <a = href='login.php'>Try Again</a>";
  }
}
?>
0
Comment
Question by:nullag
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
12 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 37769120
Here is an article that addresses PHP client authentication.  It's a good place to start.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391.html

 Your script may contain a parse error.  Add these two instructions as the first two after <?php and run it again.
ini_set('display_errors', TRUE);
error_reporting(E_ALL);

Open in new window

0
 

Author Comment

by:nullag
ID: 37769138
I added both lines of code, it still loads black

I will have a look at the link as well.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 37769203
I ran the script standalone and got some messages.  Of course it could not do anything because I do not have your data base, and I did not post any data to the script.  But at least we ruled out PHP parse errors. Try it on my server here.
http://www.laprbass.com/RAY_temp_nullag.php

Maybe if you can post the <form> script that sends its POST data to this script we can find a problem.  Just a thought, ~Ray
<?php // RAY_temp_nullag.php
ini_set('display_errors', TRUE);
error_reporting(E_ALL);

include_once 'connect.php';
session_start();

if (isset($_POST['submit']))
{
  $email=$_POST['email'];
  $password=$_POST['password'];
  $email=strip_tags($email);
  $password=strip_tags($password);
  $password=md5($password);

  $query = "SELECT * from users where email='$email' and password='$password'";
  $result = mysql_query($query) or die ("could not access users database");
  $result2 = mysql_fetch_array($result);
  if ($result2)
   {
     $_SESSION['id']=$id;

     echo "Logged In <br>";
     echo "<a href='members.php'>Continue</a>";
     exit;
  }
  else
  {
  echo "Wrong Email or Password. <a = href='login.php'>Try Again</a>";
  }
}

Open in new window

0
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

 

Author Comment

by:nullag
ID: 37769216
This is the POST (Login) page

<form method="POST" action="auth.php">
Email: <input type="text" name="email" size="55">
Password: <input type="password" name="password" size="32" mask="x">
<br>
<input type="submit" value="login" name"submit">

Open in new window

0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37789852
It's very simple
Change line 8 to:

if (isset($_POST['password']))

Open in new window


The reason? Input type=submit is not a field and thus it doesn't get sent in the POST request...
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 150 total points
ID: 37790798
Here is line 5 of the HTML form script
<input type="submit" value="login" name"submit">

Open in new window

and here is what you probably wanted to have instead.  Note the addition of the equal sign on the name attribute
<input type="submit" value="login" name="submit" />

Open in new window

Once you make that change, please try it again and post back if you still have any troubles.  These things are hard to catch because the browsers will try to render something even if you have given them invalid HTML.  But you can always feed your script to the W3 validator and it will often catch these kinds of errors and tell you about them.
http://validator.w3.org/

Best regards, ~Ray
0
 

Author Comment

by:nullag
ID: 38086067
Thanks that worked.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 38086112
You're kidding, right?  Can you please post a demonstration of how this solved the problem?

Thanks, ~Ray
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 38087172
Haha!
I was utterly wrong in the reasoning after the fact: my recipe works because it relies on the other input field.

Ray nailed it though, because he found your typo.
Please review this and award him the points.
0
 

Author Closing Comment

by:nullag
ID: 38106178
My typo
0

Featured Post

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question