Click to See Complete Forum and Search --> : Passwording a single page?


bruisr
08-16-2006, 01:52 PM
I'm looking for a simple way to set up a password on a single page that contains contact information. I just need to have a prompt that comes up when they come to that page, where they need to enter a username/password to see the page.

Is there something I can use just PHP or some other language to create the password prompt?

sae
08-16-2006, 03:05 PM
easiest would be a .htaccess (search google). It's easy to do.

bruisr
08-16-2006, 03:45 PM
Ok thanks.

bruisr
08-16-2006, 04:27 PM
Ok so I made my .htaccess and .htpasswd files, i entered the username:password that I wanted, and I uploaded them to the directory that I want protected. I surf to it, enter the username/password that I entered in my .htpassword file, and it just keeps bringing up the password prompt. I had to have done something wrong.

bokeh
08-16-2006, 05:07 PM
easiest would be a .htaccess (search google). It's easy to do..htaccess is for passwording a directory, not a single page. If you want to protect just a page with PHP place the following code at the start of the file.<?php

session_start();

$user = '*****';
$pass = '*****';

if(isset($_GET['log_out']))
{
$_SESSION = array();
if (isset($_COOKIE[session_name()]))
{
setcookie(session_name(), '', time()-86400, '/');
}
session_destroy();
header('Location: http://'.$_SERVER['HTTP_HOST'].htmlentities($_SERVER['PHP_SELF']));
die;
}
elseif(((!empty($_POST['user']) and !empty($_POST['pass']) and ($user.$pass == trim($_POST['user']).trim($_POST['pass']))) or (isset($_SESSION['logged']) and ($_SESSION['logged'] === true) and isset($_SESSION['user']) and ($_SESSION['user'] == $user))) and ($_SESSION['attempts'] < 5))
{
$_SESSION['logged'] = true;
$_SESSION['user'] = $user;
}
else
{
$_SESSION['attempts'] = isset($_SESSION['attempts']) ? ++$_SESSION['attempts'] : 0;
print '<form action="" method="post">
<p><label>Username: </label><input type="text" name="user"></p>
<p><label>Password: </label><input type="password" name="pass"></p>
<p><label>&nbsp</label><input type="submit" value="Enter"></p>
</form>';
die;
}

?>

bruisr
08-16-2006, 05:31 PM
That was actually even easier than doing the .htaccess that didnt work haha.

Thank you very much! I'm learning more every day.

bokeh
08-16-2006, 05:41 PM
add a link on your page somewhere to log out.<a href="<?php $_SERVER['PHP_SELF'] ?>?log_out">log out</a>

Crazy Heart
02-13-2007, 07:05 AM
thanks this helped me a lot!

popcop
02-13-2007, 09:22 AM
add a link on your page somewhere to log out.<a href="<?php $_SERVER['PHP_SELF'] ?>?log_out">log out</a>

PHP seems to be you FIRST language.

MrCoder
02-13-2007, 10:47 AM
.htaccess is for passwording a directory, not a single page.


<Files fileA.htm,fileB.htm,fileC.htm>
AuthName "Protected!"
AuthType Basic
AuthUserFile /www/directory/.htpasswd
require valid-user
</Files>