4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 Looking for single password login script
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
GoldiesMom
Junior WebHelper
Junior WebHelper


Joined: 13 Nov 2003
Posts: 4

PostPosted: Thu Nov 13, 2003 12:59 pm (20 years, 5 months ago) Reply with QuoteBack to Top

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!
OfflineView User's ProfileFind all posts by GoldiesMomSend Personal Message
adam
Forum Moderator & Developer



Joined: 26 Jul 2002
Posts: 704
Location: UK

PostPosted: Thu Nov 13, 2003 5:23 pm (20 years, 5 months ago) Reply with QuoteBack to Top

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...
OfflineView User's ProfileFind all posts by adamSend Personal MessageVisit Poster's Website
Darren
Team Member



Joined: 05 Feb 2002
Posts: 549
Location: London

PostPosted: Thu Nov 13, 2003 7:06 pm (20 years, 5 months ago) Reply with QuoteBack to Top

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 Embarassed
OfflineView User's ProfileFind all posts by DarrenSend Personal MessageVisit Poster's Website
GoldiesMom
Junior WebHelper
Junior WebHelper


Joined: 13 Nov 2003
Posts: 4

PostPosted: Thu Nov 13, 2003 8:38 pm (20 years, 5 months ago) Reply with QuoteBack to Top

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.
OfflineView User's ProfileFind all posts by GoldiesMomSend Personal Message
adam
Forum Moderator & Developer



Joined: 26 Jul 2002
Posts: 704
Location: UK

PostPosted: Thu Nov 13, 2003 9:18 pm (20 years, 5 months ago) Reply with QuoteBack to Top

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...
OfflineView User's ProfileFind all posts by adamSend Personal MessageVisit Poster's Website
GoldiesMom
Junior WebHelper
Junior WebHelper


Joined: 13 Nov 2003
Posts: 4

PostPosted: Thu Nov 13, 2003 10:10 pm (20 years, 5 months ago) Reply with QuoteBack to Top

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?
OfflineView User's ProfileFind all posts by GoldiesMomSend Personal Message
adam
Forum Moderator & Developer



Joined: 26 Jul 2002
Posts: 704
Location: UK

PostPosted: Thu Nov 13, 2003 10:14 pm (20 years, 5 months ago) Reply with QuoteBack to Top

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...
OfflineView User's ProfileFind all posts by adamSend Personal MessageVisit Poster's Website
GoldiesMom
Junior WebHelper
Junior WebHelper


Joined: 13 Nov 2003
Posts: 4

PostPosted: Thu Nov 13, 2003 10:16 pm (20 years, 5 months ago) Reply with QuoteBack to Top

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.
OfflineView User's ProfileFind all posts by GoldiesMomSend Personal Message
adam
Forum Moderator & Developer



Joined: 26 Jul 2002
Posts: 704
Location: UK

PostPosted: Fri Nov 14, 2003 4:57 pm (20 years, 5 months ago) Reply with QuoteBack to Top

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...
OfflineView User's ProfileFind all posts by adamSend Personal MessageVisit Poster's Website
m7d7g7
Junior WebHelper
Junior WebHelper


Joined: 10 Dec 2003
Posts: 4

PostPosted: Wed Dec 10, 2003 12:47 am (20 years, 4 months ago) Reply with QuoteBack to Top

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?
OfflineView User's ProfileFind all posts by m7d7g7Send Personal Message
Darren
Team Member



Joined: 05 Feb 2002
Posts: 549
Location: London

PostPosted: Wed Dec 10, 2003 10:41 am (20 years, 4 months ago) Reply with QuoteBack to Top

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 */
}
?>
OfflineView User's ProfileFind all posts by DarrenSend Personal MessageVisit Poster's Website
adam
Forum Moderator & Developer



Joined: 26 Jul 2002
Posts: 704
Location: UK

PostPosted: Wed Dec 10, 2003 6:32 pm (20 years, 4 months ago) Reply with QuoteBack to Top

m7d7g7, can you post the exact code you used (minus any passwords Wink)?

________________________________
It's turtles all the way down...
OfflineView User's ProfileFind all posts by adamSend Personal MessageVisit Poster's Website
m7d7g7
Junior WebHelper
Junior WebHelper


Joined: 10 Dec 2003
Posts: 4

PostPosted: Thu Dec 11, 2003 1:00 am (20 years, 4 months ago) Reply with QuoteBack to Top

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.
OfflineView User's ProfileFind all posts by m7d7g7Send Personal Message
Darren
Team Member



Joined: 05 Feb 2002
Posts: 549
Location: London

PostPosted: Thu Dec 11, 2003 8:47 am (20 years, 4 months ago) Reply with QuoteBack to Top

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>

<?
}
?>
OfflineView User's ProfileFind all posts by DarrenSend Personal MessageVisit Poster's Website
adam
Forum Moderator & Developer



Joined: 26 Jul 2002
Posts: 704
Location: UK

PostPosted: Thu Dec 11, 2003 4:30 pm (20 years, 4 months ago) Reply with QuoteBack to Top

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...
OfflineView User's ProfileFind all posts by adamSend Personal MessageVisit Poster's Website
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   


Go to page 1, 2  Next

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.298755 seconds :: 18 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme