Solved

blank screen after php auth script

Posted on 2012-03-26
12
261 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
  • 4
  • 4
  • 2
12 Comments
 
LVL 108

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 108

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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 108

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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now