PHP Cookie when login help...
Posted: Wed Feb 11, 2009 5:59 pm
Hey!
I have come up with some sort of basic script for the moment.
Heres the code for my index of the admin section:
So... The first section is the password protect code along with the login box.
The second part is my actual script which includes other pages.
My question is this:
The script works fine. But the problem is when I login the page shows, when I click to another page I have to then re-type the password in again! How can I stop this to just insert the password once and it 'remember me' for a while. I can only think of cookies but I have never used these before so I need help with this section.
Thanks.
I have come up with some sort of basic script for the moment.
Heres the code for my index of the admin section:
Code: Select all
<?php
// Define your username and password
$username = "admin";
$password = "password123";
if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) {
?>
<h1>Login</h1>
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<p><label for="txtUsername">Username:</label>
<br /><input type="text" title="Enter your Username" name="txtUsername" /></p>
<p><label for="txtpassword">Password:</label>
<br /><input type="password" title="Enter your password" name="txtPassword" /></p>
<p><input type="submit" name="Submit" value="Login" /></p>
</form>
<?php
}
else {
?>
<?php
$id = (isset($_GET['id']) ? $_GET['id'] : "home");
@include('header.php');
switch($id)
{
case "home":
@include('home.php');
break;
case "insert":
@include('insert.php');
break;
case "password":
@include('password.php');
break;
case "reset":
@include('reset.php');
break;
}
@include('footer.php');
?>
<?php
}
?>So... The first section is the password protect code along with the login box.
The second part is my actual script which includes other pages.
My question is this:
The script works fine. But the problem is when I login the page shows, when I click to another page I have to then re-type the password in again! How can I stop this to just insert the password once and it 'remember me' for a while. I can only think of cookies but I have never used these before so I need help with this section.
Thanks.