I've run into this one plenty of times. 🙂
The way I solved it (I'm sure there are multiple ways) is to pass the auto-increment field id and a MD5 hash of the number to each page. On the top of each page, just pull that ID from the database, hash the number and see if it matches the one passed in the query string.
Might sound a bit confusing, so I've included some code below:
/ This is your initial page /
$social = MD5($row[social]); // $row[social] is the number as pulled from the database
$ident = $row[id]; // This is the autonumber field from the database
echo "<a href='my_page.php?social=$social&ident=$ident'>To the page</a>\n";
===========================
/ Now the code at the top of the other pages /
// Connect to database code goes here
$result = @("SELECT ident, password from <table name> where id='$HTTP_GET_VARS[ident]'"); // Grab the info from the DB based on the ident variable
$num = @mysql_num_rows($result); // How many rows were returned??? (0 means no match)
If ($num) {
$row = @mysql_fetch_array($result); // Put the data into the $row array
$check_social = MD5($row[social]); // Create the hash to check against the one passed to the page
If ($check_social != $HTTP_GET_VARS[$social]) {
Header("Location: nice_try.php?status=go+away");
} // End of check_social
} else {
/ No rows were returned from the query /
Header("Location: nice_try.php?status=go+away");
}
Hope this helps... Feel free to e-mail with any questions.
John Cornett