Jump to content

Two Reloads, with output after input?


Thumbz

Recommended Posts

After inputing my email and password  and clicking submit, the echo in Verify_User (in bold) doesn't show up, nor does it load the logged in form of the log in bar.  If I reload the page or press submit again (even without entering any information), everything works.  At first I though I might just be outputting before getting my input on the reload, but all info is obtained at the top.  I also thought it might be $logoff, but it doesn't tell me "You logged off!", while still setting $logoff to true by the end in order to output the login menu.  Therefore, it get's passed if($Logoff) but doesn't make it to Verify_user, so for some reason $L_Email and $L_Password aren't set after the first refresh.  I'm a newbie so any help, related to the problem or not, would be greatly appreciated. :)

P.S.  The logoff button works the first time.

 

 

<?php
$L_Email = $_POST['l_email'];
$L_Password = $_POST['l_password'];
$Logoff = $_POST['logoff'];

//if the page was requested with an effort to logoff
if ($Logoff)
{ 
  //setcookie("session_email", "", time()-3600);
  setcookie("session_password", "", time()-3600);
}

//if logging in, Email and password are already set, make them cookies
else if($L_Email && $L_Password)
{ 
  setcookie("session_email", $L_Email, 0); 
  setcookie("session_password", $L_Password, 0); 
}


$L_Email = get_email_cookie();
$L_Password = get_password_cookie();
  
$logbar_html = "";
  
if($Logoff)
{ $logbar_html = $logbar_html . "You logged off!<br>"; }

else
{  
  //if there was a cookie or apt input
  if ($L_Email && $L_Password)
  {
    //if logged on
    if(verify_user($L_Email, $L_Password))
    {
      $logbar_html = $logbar_html . "Hello $L_Email!<br>"; 
      $logbar_html = $logbar_html . "<form action='index.php?at=". $_GET['at'] . "' method='post'>
        <input name='logoff' type='submit' value='logoff'>
        </form>";
      $logbar_html = $logbar_html . "<a href='index.php?at=edit_account'><text size=1>Edit your account!</text></a><br>";
      if ($L_Email == "[email protected]")
      { echo "<a href='index.php?at=admin'>Admin</a>"; }
    }
    else
    { $logbar_html = $logbar_html . "Login Failed<br>"; $Logoff=true; $L_Password=NULL; }
  }
  //if this, you are definitely logged off
  else { $Logoff = true; }
}

//if you are logged off
if($Logoff)
{
$logbar_html = $logbar_html . "<a href='index.php?at=register'><text size='0'>Register!</text></a><br>
  <form action='index.php?at=". $_GET['at'] . "' method='post'> 
  Email: <input name='l_email' type='text' value='$L_Email'/><br> 
  Password: <input name='l_password' type='password' /> <br>
  <input type='submit' />
  </form> ";
}



function get_email_cookie()
{
  $email_cookie = "";
  if(isset($_COOKIE["session_email"]))
  { $email_cookie = $_COOKIE["session_email"]; }
  
  return $email_cookie;
}

function get_password_cookie()
{
  $password_cookie = "";
  if(isset($_COOKIE["session_password"]))
  { $password_cookie = $_COOKIE["session_password"]; }
  
  return $password_cookie;
}

function verify_user($email_check, $pass_check)
{
    echo "verifying $email_check  $pass_check";

    $con = mysql_connect("my", "info", "only");
    if (!$con)
    {
     die("Could not connect: " . mysql_error());
    }
    mysql_select_db("begood4u_barter", $con);

  if(!$email_check || !$pass_check)
  { return false; }
  $result = mysql_query("SELECT Password FROM Members WHERE Email='$email_check'");
  $real_pass = "";
  if($row = mysql_fetch_array($result))
  { $real_pass = $row['Password']; }
  else { echo "$result"; }
  echo " real pass:  $real_pass";
  
  mysql_close($con);
  return($pass_check == $real_pass);
}

?>

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/233284-two-reloads-with-output-after-input/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.