Author |
Message |
GoldiesMom
Junior WebHelper
Joined: 13 Nov 2003
Posts: 4
|
Posted:
Thu Nov 13, 2003 12:59 pm (20 years, 5 months ago) |
|
I"m looking for a "what you see if what you get" script that requires a single login password by all who may use it. Can anyone help me? Thanks! |
|
|
|
|
adam
Forum Moderator & Developer
Joined: 26 Jul 2002
Posts: 704
Location: UK
|
Posted:
Thu Nov 13, 2003 5:23 pm (20 years, 5 months ago) |
|
hi there, I'm not entirely sure what you're looking for. do you mean you want something with which to generate HTML? |
________________________________ It's turtles all the way down... |
|
|
|
Darren
Team Member
Joined: 05 Feb 2002
Posts: 549
Location: London
|
Posted:
Thu Nov 13, 2003 7:06 pm (20 years, 5 months ago) |
|
My interpretation was they were after a script which will check that a password entered in a form matches a single hard-coded password and allows the user access to protected content.
if thats the case a simple IF statement would do the trick, wouldn't it. Although if it was to allow access over a series of pages you would need to create some kind of session.
I've done this using PHP sessions before, but won't embarass myself by posting any code |
|
|
|
|
GoldiesMom
Junior WebHelper
Joined: 13 Nov 2003
Posts: 4
|
Posted:
Thu Nov 13, 2003 8:38 pm (20 years, 5 months ago) |
|
I'm looking for a password protected script where everyone who logs in will use the same password. This script must work with IE 5.0 and above, and preferably but not necessarily with Netscape. |
|
|
|
|
adam
Forum Moderator & Developer
Joined: 26 Jul 2002
Posts: 704
Location: UK
|
Posted:
Thu Nov 13, 2003 9:18 pm (20 years, 5 months ago) |
|
browser compatibility isn't really an issue, since all the processing is done by the server. Something like this should do the job (assuming you're using PHP):
login.php:
Code: | <?php
if($_POST['password'] == 'yourpassword') {
$_SESSION['authed'] = TRUE;
}else{
$_SESSION['authed'] = FALSE;
/* display an error message */
}
?> |
Restricted pages:
Code: | <?php
if($_SESSION['authed']) {
/* display content */
}else{
/* error */
}
?> |
Login Form:
Code: | ...
<form action="login.php" method="post">
<input type="password" name="password" />
<input type="submit" value="Login" />
</form>
...
|
|
________________________________ It's turtles all the way down... |
|
|
|
GoldiesMom
Junior WebHelper
Joined: 13 Nov 2003
Posts: 4
|
Posted:
Thu Nov 13, 2003 10:10 pm (20 years, 5 months ago) |
|
I don't have PHP and I don't understand these codes, they're greek to me, so can you help me determine where to place them and whatever else I need to know? |
|
|
|
|
adam
Forum Moderator & Developer
Joined: 26 Jul 2002
Posts: 704
Location: UK
|
Posted:
Thu Nov 13, 2003 10:14 pm (20 years, 5 months ago) |
|
ok...if you don't have PHP, do you have any other kind of server-side script support? |
________________________________ It's turtles all the way down... |
|
|
|
GoldiesMom
Junior WebHelper
Joined: 13 Nov 2003
Posts: 4
|
Posted:
Thu Nov 13, 2003 10:16 pm (20 years, 5 months ago) |
|
I'm not sure what you mean by server-side script support, but the server that I'm using does support PHP, perl and stuff. |
|
|
|
|
adam
Forum Moderator & Developer
Joined: 26 Jul 2002
Posts: 704
Location: UK
|
Posted:
Fri Nov 14, 2003 4:57 pm (20 years, 5 months ago) |
|
ok...now that I think about it, perhaps using PHP isn't the best way of doing it. there's an article here about using .htaccess for password protection. I suggest you read that, as that would be the simplest way to do it - and would also make it easy to expand to using multiple users. |
________________________________ It's turtles all the way down... |
|
|
|
m7d7g7
Junior WebHelper
Joined: 10 Dec 2003
Posts: 4
|
Posted:
Wed Dec 10, 2003 12:47 am (20 years, 4 months ago) |
|
adam... thanks for your code. I have two quick questions.. First if they enter the password correct how can you redirect them to a protected page. When i added the restricted code to my php files that i wanted protected without loggin in, i was able to access them? Is this a problem on my end? |
|
|
|
|
Darren
Team Member
Joined: 05 Feb 2002
Posts: 549
Location: London
|
Posted:
Wed Dec 10, 2003 10:41 am (20 years, 4 months ago) |
|
Quote: | First if they enter the password correct how can you redirect them to a protected page |
that should do it, change the path to that of the page you want to redirect to.
login.php:
Code: | <?php
if($_POST['password'] == 'yourpassword') {
$_SESSION['authed'] = TRUE;
header("Location: /restricted_page.php");
exit
}else{
$_SESSION['authed'] = FALSE;
/* display an error message */
}
?> |
|
|
|
|
|
adam
Forum Moderator & Developer
Joined: 26 Jul 2002
Posts: 704
Location: UK
|
Posted:
Wed Dec 10, 2003 6:32 pm (20 years, 4 months ago) |
|
m7d7g7, can you post the exact code you used (minus any passwords )? |
________________________________ It's turtles all the way down... |
|
|
|
m7d7g7
Junior WebHelper
Joined: 10 Dec 2003
Posts: 4
|
Posted:
Thu Dec 11, 2003 1:00 am (20 years, 4 months ago) |
|
well, i put this is thats in my login.php:
Code: | <?php
if($_POST['password'] == 'pass') {
$_SESSION['authed'] = TRUE;
}else{
$_SESSION['authed'] = FALSE;
/* display an error message */
}
?> |
This is what i have at the top of my restricted page, called vip.php with all of the html stuff below it.
Code: | <?php
if($_SESSION['authed']) {
/* display content */
}else{
/* error */
}
?> |
and i have the login form in a regular HTML file. When i try to access the "vip.php" it goes right to that page without loggin in. When i enter the password in the login.html file, it just takes me to login.php. I'm i setting up the code wrong?
thanks for your help,
Mike. |
|
|
|
|
Darren
Team Member
Joined: 05 Feb 2002
Posts: 549
Location: London
|
Posted:
Thu Dec 11, 2003 8:47 am (20 years, 4 months ago) |
|
m7d7g7 wrote: |
This is what i have at the top of my restricted page, called vip.php with all of the html stuff below it.
Code: | <?php
if($_SESSION['authed']) {
/* display content */
}else{
/* error */
}
?> |
|
You say you have the HTML stuff bleow this code, if that is the case then that is the problem. The HTML you want password protected needs to be within the if statement. Something like this:
Code: | <?php
if($_SESSION['authed']) {
?>
<h1>Welcome</h1>
<p>This is the information that you want to hide from people with no password.</p>
<?
}else{
/* error */
?>
<p>Sorry you need to login to see this page</p>
<p><a href="login.php">Back to login</a></p>
<?
}
?> |
|
|
|
|
|
adam
Forum Moderator & Developer
Joined: 26 Jul 2002
Posts: 704
Location: UK
|
Posted:
Thu Dec 11, 2003 4:30 pm (20 years, 4 months ago) |
|
what darren said would work, though I personally think it would look cleaner to do this...
Code: | <?php
if(!$_SESSION['authed']) {
print '<p>You cannot view this page.</p>';
exit();
}
?> |
...at the top of any protected pages. what this'll do is print an error and kill the script if the user hasn't logged in. |
________________________________ It's turtles all the way down... |
|
|
|
|