hey
i'm creating a database driven login script, the code for which is shown below. its all on the same page, i.e. the input form is sent to the same page, where php decides whether on not to run the validateuser function.
becuase my global variables it set to off, i use http_session_vars
the problem lies, when the user has been authenticated, i return the value of http_session_vars[curentuser] out of the validate user function. this has been set to the username of the user that has been autherised. in the use:
$HTTP_SESSION_VARS = fvalidateuser($HTTP_SESSION_VARS);
to reset http_session_vars to this returned value. but i get error 500s!!!!!
what wrong? i can;t figure it out for the life of me.
and i really don't want to have to turn on global variables - this is a big project, besides i'm trying to make my code as portable as possible.
cheers for any help
dgr
<?php
session_start();
//if currentuser is not yet registered (!), register it, and set its value to null (to get rid of those those undefined errors).
if (!session_is_registered ("currentuser")){
session_register("currentuser");
$HTTP_SESSION_VARS['currentuser'] = "";
}
require("header.inc");
fopendb ($database);
//open database
//validate the user - first check if fields are filled in.
function fvalidateuser($database, $arraylogin, $table, $link, $HTTP_SESSION_VARS){
If ($arraylogin["loginusername"] == "" ){
print("<i>error - you must enter a username</i><p>");
}elseif ($arraylogin["loginpassword"] == "" ){
print("<i>error - you must enter a password</i><p>");
}else{
//next check if user in username table
$result = mysql_query("select from $table where (username='$arraylogin[loginusername]')");
$numrows = mysql_num_rows($result);
if ($numrows != 1 ){
print("error - username not found<p>");
}else{
//next check if username and password match - if they do then login.
$result = mysql_query("select from $table where (username='$arraylogin[loginusername]') and (password='$arraylogin[loginpassword]') ");
$numrows = mysql_num_rows($result);
if ($numrows != 1 ){
print("error - incorrect password<p>");
}else{
$HTTP_SESSION_VARS['currentuser'] = $arraylogin["loginusername"];
print("Successfully logged in. Please use the menu to the left to navigate the system.<p>");
return $HTTP_SESSION_VARS;
}
}
}
}
If (isset($POST["arraylogin"])){ //if the post(arraylogin) is set, that is has been passed on from the form, then set $arraylogin to its value.
$arraylogin = $POST["arraylogin"];
$table = "username";
fvalidateuser ($database, $arraylogin, $table, $link, $HTTP_SESSION_VARS);
//call function fvalidateuser
$HTTP_SESSION_VARS = fvalidateuser($HTTP_SESSION_VARS);
//let $HTTP_SESSION_VARS['currentuser'] equal the returned value, that is change the currentuser to the new user.
}
If ($HTTP_SESSION_VARS['currentuser'] == "") {
print <<<output
<b>Please enter your username and password</b><p>
<form action="index.php" method=post>
Username <input type=text name="arraylogin[loginusername]" size=10><br>
Password <input type=password name="arraylogin[loginpassword]" size=10><br>
<input type=submit name="submit" value="Login">
</form>
output;
}
require("footer.inc");
?>