script works, but doesnt work :S
Posted: Mon Mar 01, 2004 11:24 am
ok, here some background on what the script is supposed to do
i have also built the registration form successfully fyi
basically here we have a login script, its designed to well log people in, when a persons credentials have been verified against mysql its supposed to set some $var's and then redirect (header location way) unfortunately the script is not setting the var whatsoever, i tried changing the url it passes to just to make sure my ID was correct and it is so technically the $vars should get set
heres the code
now the login form is on the index page and i am therefore basically redirecting to that page, i dont know if this is the problem (cant see any good reason why it would be)
i also thought maybe it was a header problem but alas, it isnt, i also thought it could be that i you cannot set a var whilst redirecting but ive done it before so it cant be
also to check on the index page i written this script
still it keeps tellin me that it aint working when my ID is correct
any ideas peeps?
i have also built the registration form successfully fyi
basically here we have a login script, its designed to well log people in, when a persons credentials have been verified against mysql its supposed to set some $var's and then redirect (header location way) unfortunately the script is not setting the var whatsoever, i tried changing the url it passes to just to make sure my ID was correct and it is so technically the $vars should get set
heres the code
Code: Select all
<?php
require ("dbhandler.php");
require ("datehandler.php");
// lets turn the posted vars into better looking vars
$loginusername = $_POST["login_username"];
$loginpassword = $_POST["login_password"];
// now lets strip just in case of formatting mistakes
$loginusername = stripslashes($loginusername);
$loginpassword = stripslashes($loginpassword);
// check that both variables have been set
if
((!$loginusername) || (!$loginpassword))
{
header("Location: ../index.php");
exit();
}
//now lets turn the password into MD5 format
$md5pass = md5($loginpassword);
// now we have converted and formatted all the vars lets run a MYSQL query
$loginquery = mysql_query("SELECT username FROM members WHERE username = '$loginusername' AND password = '$md5pass'");
// now lets see if theres a match already in the database
$loginauth = mysql_num_rows($loginquery);
if
(($loginauth > 0))
{
// time to update the last login date for this user
$updatelastlogin = mysql_query ("UPDATE members SET last_login=now() WHERE username='$loginusername'") or die(mysql_error());
$logged_in = "yes";
$hellousername = "$loginusername";
// and now set the users status as logged in
// now to set some variables so its perfectly clear the user is logged in
// this user has been verified and given access
header("Location: ../index.php");
}
else
{
// this user cannot be found in the database
unset($loginusername);
unset($loginpassword);
header("Location: ../index.php");
}
exit();
?>i also thought maybe it was a header problem but alas, it isnt, i also thought it could be that i you cannot set a var whilst redirecting but ive done it before so it cant be
also to check on the index page i written this script
Code: Select all
<?php
if(isset($hellousername))
{
print "You are logged In";
}
else
{
print "nope, not working";
}
?>any ideas peeps?