Forum Moderators: coopster
<?php
// Define your username and password
$username = "guest";
$password = "letmein";
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 {
?>
<p>
Gallery PHP script here that has an array function that does looping through photos. LONG stuff here.
</p>
<?php
}
?>
So the problem I have is that every time I click for the next photo in the array on the page, it asks me again for the password. Is there a way to password protect the page on the first entry only?
There are varying techniques of "maintaining state" including hidden form fields (<input type="hidden"...>), cookies, sessions, etc. Basically, certain *pieces* of information are left on the client-side which help the server recognize the request coming from a previous requester, and the server can use the *stored* information left over from the last request to do more processing.
There are a number of ways to incorporate password protection. One of the most common and most secure (overall) is Session Handling [php.net].