<html>
<body>
<form method="post" action="form2.php">
Username: <input type="text" name="uname">
Password: <input type="password" name="pw">
<input type="submit"><input type="reset">
</body>
</html>
Once this information is filled out and the user hits the submit button, the form data will get 'posted' to 'form2.php' as per the instructions in the <form> tag. Let us say we only want to allow users who enter the username 'admin' and the password 'secretWord' to view the data on form2.php, and all others to be redirected back to the form.php page to retry their password. Form2.php could be coded as:
<html>
<head>
<?php
if (($uname != "admin") && ($pw != "secretWord"))
{print "<script>alert('Sorry, wrong username/password');";
print "location.href='form.php';</script>";
}
?>
</head>
<body>
Welcome to the admin screen!
You entered the correct username: <?php print $uname; ?> and password: <?php print
$pw; ?>
</body>
</html>
You will notice that the form variables passed to the second page are passed as the name of the form field preceded by a $ sign. Thus if you have:
<input type="text" name="thisVar">
It would be passed when the information was posted to the form action page as:
$thisVar
URL variables are passed in much the same way. URL variables are usually passed in href anchor tags, and are always in the format:
location.ext?var1=value1&var2=value2&var3=value3