-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Whilst lounging around on Sat, 05 Jul 2003 23:55:02 GMT, Ralph
Freshour <ra***@primemail.com> amazingly managed to produce the
following with their Etch-A-Sketch:
I bought the PHP and MySQL For Dummies book and I'm having trouble
understanding how I use PHP to verify and check forms input text
data - the book shows snippets of code so I know how to do the
actual check but I don't understand what web page the php checking
code should go into?
For example, I have a simple login web page (username and password)
and then it calls my mainmenu php web page - I want to make a check
that a username was actually typed in *before* calling the mainmenu
php page - I also know that I can do this check using javascript
but I'd like to stay in php if I can - how can I make the check and
stay on this login form before calling the mainmenu page?
Thanks...
Assuming you have 'username' and 'password' as your form text fields,
and your method is POST:
<?php
if (!preg_match("/([a-zA-Z_.-]+)/", $_POST['username'])) {
@header('Location: http://' .
$_SERVER['HTTP_HOST'] .
'/login.php'
);
}
if (!empty($_POST['password'])) {
// do check for password match
if (md5($_POST['password']) == $required_password) {
@header('Location: http://' .
$_SERVER['HTTP_HOST'] .
'/mainmenu.php'
);
} else {
die('Invalid login');
}
?>
This isn't a coplete solution as you'll need to fill out the
commented areas, but should do what you're after =)
HTH.
Regards,
Ian
-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0
iQA/AwUBPwdr92fqtj251CDhEQJZ2ACfSxH6N4JBiaHnMl8wIJxL+4 Whfy0AoIfT
8wKHusl/p2M0a6HBdp01qcEb
=g6N7
-----END PGP SIGNATURE-----
--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.