Password Protect Directories

Questions and discussions regarding web-scripting languages like HTML and PHP.

Moderator: Community Moderators

muto
Posts: 417
Joined: Sat Mar 29, 2008 12:46 pm

Re: Password Protect Directories

Post by muto » Mon Apr 27, 2009 10:08 pm

Try these files:


htaccess

Code: Select all

AuthUserFile public_html/staff/.htpasswd
AuthGroupFile public_html/staff/.htgroup
AuthName Staff Intranet
AuthType Basic

<Limit GET>
require group Staff
</Limit>
htgroup

Code: Select all

Staff:test1 test2
htpasswd

Code: Select all

test1:$apr1$.axzFc1I$PRF.U46UfTWspScpKnYJM/
test2:$apr1$BpvkohtK$g0RrYZZCmZT6IL7uWhRQy/
Username:passwords are test1:test1 and test2:test2. Make sure the paths are correct in .htaccess

Also, if the server was *NIX, then the / at the start of the paths would mean it points to the wrong place..

User avatar
ICT Tech
Community Master Admin
Posts: 1415
Joined: Thu Jul 26, 2007 6:33 pm
Location: In my chair!

Re: Password Protect Directories

Post by ICT Tech » Tue Apr 28, 2009 1:08 am

No, it didn't take that either, still got the huge error on the screen :(
ICT Tech
Senior Community Admin

muto
Posts: 417
Joined: Sat Mar 29, 2008 12:46 pm

Re: Password Protect Directories

Post by muto » Tue Apr 28, 2009 7:30 am

I can't really think of much else to try, so try sending an email to cpanel@hosting24.com and see if it's a server problem...

User avatar
ICT Tech
Community Master Admin
Posts: 1415
Joined: Thu Jul 26, 2007 6:33 pm
Location: In my chair!

Re: Password Protect Directories

Post by ICT Tech » Tue Apr 28, 2009 8:26 pm

muto wrote:I can't really think of much else to try, so try sending an email to cpanel@hosting24.com and see if it's a server problem...
That's another problem, I don't even know who hosting24.com is, i'm not even with them :cry:
I don't know what to do know, it's just not working, I'll send an email to my host and see if they can do something their end.

Cheers :P
ICT Tech
Senior Community Admin

muto
Posts: 417
Joined: Sat Mar 29, 2008 12:46 pm

Re: Password Protect Directories

Post by muto » Tue Apr 28, 2009 9:00 pm

You can quickly create a php login page (just set a session variable, and then check for it later). Have all the pages in the staff folder do a header redirect to the login page, then exit, if they don't see the variable set.

User avatar
ICT Tech
Community Master Admin
Posts: 1415
Joined: Thu Jul 26, 2007 6:33 pm
Location: In my chair!

Re: Password Protect Directories

Post by ICT Tech » Wed Apr 29, 2009 7:50 pm

muto wrote:You can quickly create a php login page (just set a session variable, and then check for it later). Have all the pages in the staff folder do a header redirect to the login page, then exit, if they don't see the variable set.
I hate php pages, how would you like to talk me through it, I find php really awkward.
P.S. 1 post away from being a power member muto! :P
ICT Tech
Senior Community Admin

User avatar
ICT Tech
Community Master Admin
Posts: 1415
Joined: Thu Jul 26, 2007 6:33 pm
Location: In my chair!

Re: Password Protect Directories

Post by ICT Tech » Wed Apr 29, 2009 7:50 pm

muto wrote:You can quickly create a php login page (just set a session variable, and then check for it later). Have all the pages in the staff folder do a header redirect to the login page, then exit, if they don't see the variable set.
I hate php pages, how would you like to talk me through it, I find php really awkward.
P.S. 1 post away from being a power member muto! :P
ICT Tech
Senior Community Admin

muto
Posts: 417
Joined: Sat Mar 29, 2008 12:46 pm

Re: Password Protect Directories

Post by muto » Wed Apr 29, 2009 7:52 pm

Give me 10 minutes, and I'll post up some code you can use..

Also, double post :P

Save this as index.php in the staff folder.

Code: Select all

<?
session_start();
if (isset($_POST['username']) && isset($_POST['password']))
{
	if ($_POST['username'] == "test" && $_POST['password'] == "test")
	{
		$_SESSION['login'] = 1;
	}
	if ($_SESSION['login'])
	{
		header("Location: main.php");
		exit;
	}
}
?>
	<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="index.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Staff Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="password" type="text" id="password"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
Then, at the top of every page in the staff folder, add the following code (save as .php, not .htm).

Code: Select all

<?php
session_start();
if (!isset($_SESSION['login']))
{
	header("Location: index.php");
	exit;
}
?>

User avatar
ICT Tech
Community Master Admin
Posts: 1415
Joined: Thu Jul 26, 2007 6:33 pm
Location: In my chair!

Re: Password Protect Directories

Post by ICT Tech » Wed Apr 29, 2009 9:55 pm

muto wrote:Give me 10 minutes, and I'll post up some code you can use..
Thanks, i'll try these in a sec!
muto wrote:Also, double post :P
Yeah, I just seen that!
Dunno what happened :lol:
ICT Tech
Senior Community Admin

muto
Posts: 417
Joined: Sat Mar 29, 2008 12:46 pm

Re: Password Protect Directories

Post by muto » Fri May 01, 2009 4:35 pm

Did the code work for you?

Post Reply