Jump to content

echo "...


ilikephp

Recommended Posts

You cannot output anything prior to calling header. Without seeing more code, I'm going to provide a simple example of what I think your looking for.

 

<?php session_start(); ?>
<form method="post">
  <input type="text" name="uname"> Username ? <?php echo isset($_SESSION['error']['uname']) ? $_SESSION['error']['uname']) : ''; ?>
  <input type="password" name="upass"> Password ? <?php echo isset($_SESSION['error']['upass']) ? $_SESSION['error']['upass']) : ''; ?>
  <input type="submit" name="submit">
</form>
<?php
if (isset($_POST['submit'])) {
  // Check username / password.
  // These values would come from the database.
  $username = 'foo';
  $userpass = 'bar';

  if ($_POST['uname'] != $username) {
    $_SESSION['error']['uname'] = "You provided an invalid username";
    header("Location http://yourserver.com/thispage.php");
    exit();
  } else {
    if (isset($_SESSION['error']['uname'])) {
      unset($_SESSION['error']['uname']);
    }
  }

  if ($_POST['uname'] != $password) {
    $_SESSION['error']['upass'] = "You provided an invalid password";
    header("Location http://yourserver.com/thispage.php");
    exit();
  } else {
    if (isset($_SESSION['error']['upass'])) {
      unset($_SESSION['error']['upass']);
    }
  }
  // here you can log your users in.
}
?>

 

Keep in mind that I don't think its a good idea to be so verbose about wether or not the user got there username or passowrd incorrect. I don't usually let them know which one they got right. A simple "Either your username or passowrd is invalid" is a better option.[/code]

Link to comment
https://forums.phpfreaks.com/topic/141908-echo/#findComment-743059
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.