|
Posted by Markus Ernst on 01/21/06 15:20
chris_fieldhouse@hotmail.com schrieb:
> Hi fairly new to php, but picking it up quite well.
> the question I have, is it possible for a php script which is used to
> validate values submitted in a form, to then post these values onto
> another script/page or even back to the calling form?
>
> i.e. the application I have in question is a login.htm page with a
> verify.php script
> The login.htm has a Form which captures login_id and password which are
> posted to verify.php
>
> verify.php checks the id and password against the database.
> if the check succeeds I use $_SESSION to track the logged in user into
> the page.
> if the check fails, I use $_SESSION["error"] to set an error message
> and then jump to login.htm, but I've lost the userid.
http://www.alt-php-faq.org/local/55/#id55
Anyway cou can do it easier - don't post to verify.php, but implement
the verify mechanism in login.php:
<?php
if (isset($_POST['user'])) {
$user = $_POST['user'];
$password = $_POST['password'];
$check = your_login_check_function($user, $password);
if ($check) {
$_SESSION['logged'] = $_POST['user'];
header("Location: your_welcome_page.php");
exit;
}
else {
$msg = "Login incorrect, try again!";
}
}
else {
$user = "";
$password = "";
$msg = "Please log in!";
}
?>
<html>
<head>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<h1><?php echo $msg; ?></h1>
<p>Username: <input type="text" value="<?php echo $user; ?>"
name="user"></p>
<p>Password: <input type="text" value="<?php echo $password; ?>"
name="password"></p>
<p><input type="submit" value="Send" name="send"></p>
</form>
</body>
</html>
[Back to original message]
|