White screen of DEATH on login script


#1

Hello Everyone,

I’m having an issue with my code. I’m basically getting a white screen as soon as it has run. I’ve tried ways of getting it to display an error message but to no avail, no matter what I try to get an error message to display. I’ve also tried to correct the problem but to no avail either. here is the code:
[php]<?php
// dBase file
include “DBC.php”;
mysql_ping();

if (!$_POST[“UserName”] || !$_POST[“Password”])
{
die(“You need to provide a username and password.”);
}
// Create query
$username = $_POST[“UserName”];
$username = mysql_real_escape_string($username);
$password = $_POST[“Password”];
$password = mysql_real_escape_string($password);
mysql_select_db(“jamesl_bromleyduties”);
$q = “SELECT MemberID FROM Members WHERE MemberUsername = ‘$username’ AND MemberPassword = ‘$password’”;
// Run query
$r = mysql_query($q) or die(mysql_error());
$count = mysql_num_rows($r) or die(mysql_error());
if ( !$count == 1 )
{
// Login not successful
die(“Sorry, could not log you in. Wrong login information.”);
} else
{
$r = mysql_query($q) or die(mysql_error());
$id = mysql_result($r);
setcookie(“User”, $id, time()+3600);
Header(“Location: main.php”) or die(mysql_error());
}
?>[/php]

After some error testing I located the issue at the [php]Header(“Location: main.php”)[/php]. I’ve checked main.php to see if there are any errors with that, but that is working fine.

The code above does register the cookie and allows me to access controlled page but it will not redirect me to the page: main.php. Just gives me a blank white screen.

Hope someone can help me, if more detail is required please let me know

Regards

James


#2

Well, code looks good… What is on the main.php file? Does it display something or is it just php code?

Also, when you run this code, and it goes to the main.php file, can you actually see the file name in the address line of the browser? If so, then that code is working and it is a problem with your code in the main.php file.

So, run it again. Look at the browser’s address line when you get the white-screen. See if it is correct. (in other words says “www.yourdomain.com/main.php”.) If so, this code is working 100% correctly! Then, look at your main.php code and see what it is supposed to be displaying. Or, add an echo near the top of it. Something like this: (In main.php’s first part of the PHP code.) echo “got here!”; and next line die(“working!”); This will let you see if you are really getting to the main.php file. Good luck…


#3

It displays a php web page, I’ve just checked what you said, it displays www.thedomain.com/login.php. So it hasn’t moved to main.php


#4

Just realized… Not sure if Header is capitalized. I think it should be header, not Header…

(Some servers may allow caps, but, standard is no caps.)

I didn’t try it, let us know…


#5

Tried that, didn’t work.


#6

Okay, next, let’s try some of the obvious debug tests…

First, you are using a mysql_ping() function at the beginning of your code. But, you are not actually pinging anything. I have never found this to be needed. Is there some special reason you are using it? And, why do you not have any site to ping to in the argument? Not sure, but, I think the default is 127.0.0.0 which is the local system? Why ping that?

Next, add this at the top of the PHP file:
[php]
error_reporting(E_ALL);
ini_set(‘display_errors’, ‘1’);
[/php]
What this does is to show you ALL errors of all types in your outputted page. This will show errors that are hidden by default. (Helps in some instances…)

Next, after this line:
$count = mysql_num_rows($r) or die(mysql_error());
add this:
[php]
echo $count;
die(“Got Here, Forced Stop!”);
[/php]
This will verify that we are getting to this point and got a value from the database!

All of these will tell us if your code is getting the data from the database.
So, debugging is basically solving a puzzle. Go step by step and verify each step is working and move on to the next step. Once you locate the error, fix it… LOL… Sounds easy, but, not always!

I am here on and off today and all day tomorrow, let’s get this fixed!