hello. i am currently rewriting and updating my code in regards to having register_globals turned off. the login script consist of three functions all in the same page.
first function is the login form:
function loginForm() {
htmlHeader();
?>
<form method="POST" action="<?php echo $_SERVER[PHP_SELF] ?>">
<input type="hidden" name="cmd" value="added">
<table align="center" cellpadding=2 cellspacing=0 border=0>
<td class="formText">Username:</td>
<td>
<input type="text" name="userid" size=10 class="textBox">
</td>
<td class="formText">Password:</td>
<td>
<input type="password" name="userpassword" size=10 class="textBox">
</td>
<td> </td><td><input type="submit" name="submit" value="log in" class="formButtons"></td>
</table>
</form>
<?
htmlFooter();
}
the form is then checked with an this:
session_start();
if(!isset($_POST['userid']) && !isset($_POST['userpassword'])) {
loginForm();
exit;
}
else {
$_SESSION['userid'] = $_POST['userid'];
$_SESSION['userpassword'] = $_POST['userpassword'];
$loginID = $_POST['userid'];
$loginPassword = $_POST['userpassword'];
$user = authUser($loginID, $loginPassword);
if(!$user) {
echo "Wrong Password";
unset($_SESSION['userid']);
unset($_SESSION['userpassword']);
loginForm();
exit;
}
}
and the last bit of code verifies the info in the mysql DB:
function authUser($loginID, $loginPassword) {
global $admintable;
$loginID = $_POST['userid'];
$loginPassword = $_POST['userpassword'];
$linkID = db_connect('guernica');
$result = mysql_query("SELECT count(*) FROM $admintable WHERE userid = '$loginID' AND userpassword = password('$loginPassword')", $linkID);
while($row = mysql_fetch_row($result)) {
if($row[0] < 0) {
return 0;
}
else {
if($row[0] > 0) {
return $row[0];
}
}
}
}
everything works fine if the user enters the correct login, it sends them to the admin page, but anytime they click an option like to add a news item it takes them back to the login page. i have no clue what is going on.
so if they wanted to add a news item the address bar would look like this:
domain.com/admin.php?cmd=newsPage&userid=userid
any help would greatly be appreciated!