Hello All,
I'm having issues with my login script. Basically, my protected page has an "included" login.php page. When the users enters the username/password correctly the first time, all is okay. But how do I pass the variable again if the login is incorrect? I am using sessions and have initialized the variable, but it doesn't seem to be working across pages.
I apologize if this is such a basic question. I've tried passing the variable in a hidden field to the protected page, but it isn't working. When I print out the variable, it's blank.
Here's the login.php page:
PHP
include ("../includes/include.php");
$id=$_GET['id']; <---- to determine content on protected page
session_set_cookie_params(3600); //set expire time
session_start();
// convert username and password from POST or SESSION
if($POST["username"])
{
$username=trim($POST["username"]);
$password=trim($POST["password"]);
$id=$GET["id"];
}
elseif($SESSION["username"])
{
$username=$SESSION["username"];
$password=$SESSION["password"];
$id=$GET["id"];
}
// start and register session variables
session_register("username");
session_register("password");
session_register("id");
// query for a user/pass match
//QUERY GOES HERE TO DB --- snip ---
$num=mysql_num_rows($result);
// print login form and exit if failed.
if($num < 1){
session_destroy();
//SHOW FORM
<form action="protectedpage.php" method=post>
<input type=text name=username><BR>
<input type=password name=password><BR>
<input type=hidden name=get_id value="<? echo "$id" ?>">
<p><input type=submit name=btnLogin value="Log In"></p>
</form>
On my "protectedpage.php" at the top I have:
<?
include("login.php")
$get_id=$_POST['get_id'];
?>
Printing out this variable is showing nothing. Any help on this will be greatly appreciated!
Thanks.
Geogal
๐