Jump to content


Photo

Blank screen on successful login


  • Please log in to reply
22 replies to this topic

#1 strawbshaker

strawbshaker
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 30 July 2006 - 02:50 PM

Hi everyone,

I am having trouble with a snipet of login code that I am working on. most of it seems to be working fine as all the following work:
- The login failed screen comes up when the username and password are entered incorrectly and don't match what is held in the database.
- When login is successful the database is updated accordingly with the date/time of last login.

What doesn't happen though is the login successful screen appearing. I think it might have something to do with the following line of code:
header("Location: /loggedin.php");

Can anyone help? The full code for my login.php is below:

<?php
include $_SERVER['DOCUMENT_ROOT'].'/common.php';
include $_SERVER['DOCUMENT_ROOT'].'/layout.php';

$req = (!isset($_REQUEST['req'])) ? 'default' : $_REQUEST['req'];
switch($req){ 
   
case "validate":
   $validate = mysql_query("SELECT * FROM dbtable
                           WHERE username='{$_POST['username']}'
                           AND password = md5('{$_POST['password']}')
                           AND verified='1'
                           ") or die (mysql_error());
                           
   if(mysql_num_rows($validate) == 1){
      while($row = mysql_fetch_assoc($validate)){
         $_SESSION['login'] = true;
         $_SESSION['userid'] = $row['id'];
         $_SESSION['first_name'] = $row['first_name'];
         $_SESSION['last_name']  = $row['last_name'];
         $_SESSION['email_address'] = $row['email_address'];
         setcookie('userid', $unique_userid, time()+24*3600*60);
         
         if($row['admin_access'] == 1){
            $_SESSION['admin'] = true;
         }
         $login_time = mysql_query("UPDATE dbtable
                       SET last_login=now()
                       WHERE id='{$row['id']}'");
       }
       session_write_close();
       header("Location: http://www.mydomain.com/loggedin.php");
   } else {
      myheader("Login Failed!");
      echo '<p align="center">Login Failed</p>';
      echo '<p align="center">Your user name or password '.
           'is incorrect. Passwords are case sensitive. '.
           'Please check and try again.';
      myfooter();
   }
break;

default:
   myheader("Login!");
      include $_SERVER['DOCUMENT_ROOT'].
              '/html/forms/login_form.htm';
   myfooter();
break;
}

?>


#2 mainewoods

mainewoods
  • Members
  • PipPipPip
  • Advanced Member
  • 685 posts
  • LocationMaine

Posted 30 July 2006 - 03:07 PM

before you do a
header("Location:???");
you should use
session_write_close();
to make sure that the session variables are actually updated.  I assume loggedin.php accesses the session variables for security.

#3 strawbshaker

strawbshaker
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 30 July 2006 - 03:24 PM

I have tried inserting the following as suggested:
$login_time = mysql_query("UPDATE dbtable
                       SET last_login=now()
                       WHERE id='{$row['id']}'");
       }
       session_write_close(); 
       header("Location: /loggedin.php");

I have tried using set cookie recommended in anther thread and that hasn't worked either.

#4 strawbshaker

strawbshaker
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 30 July 2006 - 03:34 PM

Is ther a better line of code that I can use instead of:

header("Location: /loggedin.php");


#5 mainewoods

mainewoods
  • Members
  • PipPipPip
  • Advanced Member
  • 685 posts
  • LocationMaine

Posted 30 July 2006 - 03:35 PM

Sometimes the
header("Location:???");
requires a fully qualified url: 'http://???' it does on my system.

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 30 July 2006 - 03:47 PM

Try this when you login should goto google ok.
<?php
include $_SERVER['DOCUMENT_ROOT'].'/common.php';
include $_SERVER['DOCUMENT_ROOT'].'/layout.php';

$req = (!isset($_REQUEST['req'])) ? 'default' : $_REQUEST['req'];
switch($req){ 
   
case "validate":
   $validate = mysql_query("SELECT * FROM dbtable
                           WHERE username='{$_POST['username']}'
                           AND password = md5('{$_POST['password']}')
                           AND verified='1'
                           ") or die (mysql_error());
                           
   if(mysql_num_rows($validate) == 1){
      while($row = mysql_fetch_assoc($validate)){
         $_SESSION['login'] = true;
         $_SESSION['userid'] = $row['id'];
         $_SESSION['first_name'] = $row['first_name'];
         $_SESSION['last_name']  = $row['last_name'];
         $_SESSION['email_address'] = $row['email_address'];
         
         if($row['admin_access'] == 1){
            $_SESSION['admin'] = true;
         }
         $login_time = mysql_query("UPDATE dbtable
                       SET last_login=now()
                       WHERE id='{$row['id']}'");
       
       header("Location: http://www.google.com");
}
   } else {
      myheader("Login Failed!");
      echo '<p align="center">Login Failed</p>';
      echo '<p align="center">Your user name or password '.
           'is incorrect. Passwords are case sensitive. '.
           'Please check and try again.';
      myfooter();
   }
break;

default:
   myheader("Login!");
      include $_SERVER['DOCUMENT_ROOT'].
              '/html/forms/login_form.htm';
   myfooter();
break;
}

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 strawbshaker

strawbshaker
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 30 July 2006 - 03:49 PM

I have added/updated the following code in my mai script and still no joy:

setcookie('userid', $unique_userid, time()+24*3600*60);

session_write_close();
header("Location: http://www.mydomain.com/loggedin.php");

Any other advise? Thank you to those who have already contributed.

#8 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 30 July 2006 - 03:51 PM

did you try my code you goto use a header the close of the if statement try it ok.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#9 mainewoods

mainewoods
  • Members
  • PipPipPip
  • Advanced Member
  • 685 posts
  • LocationMaine

Posted 30 July 2006 - 03:58 PM

Try putting this code:

<?php
    echo "made it here!";
    exit; //no more code executed
?>
at the top of your 'loggedin.php' page.  Maybe that page has an error in it.  Maybe a syntax error, try calling the page directly from the address field of your browser with the code above in it.

#10 para11ax

para11ax
  • Members
  • PipPip
  • Member
  • 21 posts
  • LocationColumbus, OH

Posted 30 July 2006 - 04:06 PM

Can you post the login form?  I'm used to login forms sending $_POST variables.  Could that be the problem, or does your login form process itself and then send the user to this validation page with the  POST variables as REQUEST variables?

Though, if this is the case it should still go to default, but it seems like it's worth a shot.

#11 strawbshaker

strawbshaker
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 30 July 2006 - 04:08 PM

I have moved the header() as suggested by redarrow and changed to content of my loggedin.php fole to check if the error is there. I have combed through every possible connecting script to check for errors and I can't find any thing wrong. I feel like crying as I got stuck on this when I went to bed last night and have been working on it all day so far and haven't got any where. AAAGGGHHH!!!

Thanks for trying to help though and keep the suggestions coming! i really appreciate any help.

#12 strawbshaker

strawbshaker
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 30 July 2006 - 04:20 PM

here's the login_form.htm:

<div align="center">Please Login</div>

<form action="/login.php" method="post">
  <table width="30%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr> 
      <td width="19%">Username:</td>
      <td width="81%"><input name="username" type="text" id="username" value="<?=$_POST['username'];?>" /></td>
    </tr>
    <tr> 
      <td>Password:</td>
      <td><input name="password" type="password" id="password" /></td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td><div align="center">
          <input type="hidden" name="req" value="validate" />
          <input type="submit" name="Submit" value="Submit" />
        </div></td>
    </tr>
  </table>
</form>


#13 mainewoods

mainewoods
  • Members
  • PipPipPip
  • Advanced Member
  • 685 posts
  • LocationMaine

Posted 30 July 2006 - 04:23 PM

did you just try entering ' http://www.mydomain.com/loggedin.php' directly into the browser address field to try to bring up that page by itself and make sure there is nothing wrong with that page?

#14 strawbshaker

strawbshaker
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 30 July 2006 - 04:28 PM

I tried that and the loggedin.php page came up no problem.

Have I missed a slash, colon or anything like that anywhere that might be causing this error?

#15 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 30 July 2006 - 04:30 PM

POST upercase in the form ok.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#16 mainewoods

mainewoods
  • Members
  • PipPipPip
  • Advanced Member
  • 685 posts
  • LocationMaine

Posted 30 July 2006 - 04:37 PM

I don't see
session_start();
in your code, is it in one of the 'includes' above?

#17 para11ax

para11ax
  • Members
  • PipPip
  • Member
  • 21 posts
  • LocationColumbus, OH

Posted 30 July 2006 - 04:41 PM

Correct me if I'm wrong, but post variables go into the $_POST array, so you should change the line:

$req = (!isset($_REQUEST['req'])) ? 'default' : $_REQUEST['req'];

to:

$req = (!isset($_POST['req'])) ? 'default' : $_POST['req'];


#18 strawbshaker

strawbshaker
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 30 July 2006 - 04:51 PM

I ahve just noticed that when I get the blank screen the web address bar says I an still on login.php and not loggedin.php.

#19 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 30 July 2006 - 04:53 PM

<div align="center">Please Login</div>

<form action="/loggedin.php" method="POST">
  <table width="30%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr> 
      <td width="19%">Username:</td>
      <td width="81%"><input name="username" type="text" id="username" value="<?=$_POST['username'];?>" /></td>
    </tr>
    <tr> 
      <td>Password:</td>
      <td><input name="password" type="password" id="password" /></td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td><div align="center">
          <input type="hidden" name="req" value="validate" />
          <input type="submit" name="Submit" value="Submit" />
        </div></td>
    </tr>
  </table>
</form>


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#20 strawbshaker

strawbshaker
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 30 July 2006 - 05:00 PM

session_start(); is in the one of the includes. The code used looks like this:

session_start();
session_name('ClientLogin');
header("Cache-control: private"); //Fix for IE

I have tried replacing $_REQUEST with $_POST and I am still getting the same result. Should the form method for the form in login_form.htm not be $_POST instead of just POST maybe?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users