Free Web Hosting PHP/mySQL
GlobalWeb.com.ru Forum Index GlobalWeb.com.ru
Free Web Hosting :: Commercial Web Hosting :: PHP/mySQL :: CGI/Perl
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

password protect pages???

 
Post new topic   Reply to topic    GlobalWeb.com.ru Forum Index -> PHP
Author Message
asiammyself
Guest





PostPosted: Sat Feb 28, 2004 5:52 am    Post subject: password protect pages??? Reply with quote

how do you password protect pages? Question
Back to top
Smith
Guest





PostPosted: Sat Feb 28, 2004 3:21 pm    Post subject: Hey this is how Reply with quote

You 1st have to have PHP. If you dont stop reading.
Ok since am just 14 and not good at PHP so much I can't give u the code. However the BEST site is www.hotscripts.com/PHP
Back to top
ReV[a]N



Joined: 27 Feb 2004
Posts: 3

PostPosted: Sat Feb 28, 2004 5:27 pm    Post subject: PHP Authentication Reply with quote

You might want to consider posting this in the help part of the forum not the Howtos section, but here is one way.

Code:
/*********************************************************
**
**   userAuth.php
**
*********************************************************/

/*********************************************************
**
**   checkAuth(string "$username", string "$password");
**
**   Takes the $username and $password variables
**   and checks to see if they match the $PHP_AUTH
**   variables.
**
*********************************************************/

function checkAuth()
{
   /* Later you can add user permissions so just some users can view certain pages */

   /* When you make your own database (if you use one) you can change the table names and field names to match your own database */
   $sql = "select * from users where username='$PHP_AUTH_USER' AND password='$PHP_AUTH_PW'";
   $query = mysqL_query($sql);
   $row = mysqL_fetch_array($query);
   $username = $row[username];
   $password = $row[password];
   
   if (!isset($PHP_AUTH_USER))
   {
      header('WWW-Authenticate: Basic realm="CPS Administration"');
      header('HTTP/1.0 401 Unauthorized');
      echo 'Authorization Required.';
      exit;
   }
   else
   {
      /* If he has tried to log in but has failed and tries again */
      if (($PHP_AUTH_USER != "$username") || ($PHP_AUTH_PW != "$password"))
      {
         header('WWW-Authenticate: Basic realm="CPS Administration: Incorrect Username/Password"');
         header('HTTP/1.0 401 Unauthorized');
         echo "Autorization Required.";
         exit;
      }
      else
      {
         /* If the username and password were correct do nothing*/
         break;     
      }
   }
}


Code:
/*********************************************************
**
**   index.php
**
*********************************************************/

/*********************************************************
**
**   Common Files
**
*********************************************************/
require("common/userAuth.php");

/*********************************************************
**
**   User Authentication
**
*********************************************************/
checkAuth();

/*********************************************************
**
**   User Authentication
**
*********************************************************/

/* Put code here that runs when the user is logged in, $PHP_AUTH_USER is the variable to print the username of the person logged in */
echo "Yay The Page is Displaying!";


You can add more functions to userAuth.php, maybe add a user level (user, moderator, admin) or something else.
Back to top
View user's profile Send private message
Nocturnal



Joined: 28 Feb 2004
Posts: 3

PostPosted: Sat Feb 28, 2004 6:01 pm    Post subject: Reply with quote

You don't necessarily need PHP if you don't have to have secure. Actually, here's a pretty simple way to do a JavaScript one:
Code:

<html>
<head>
<title>Password Test</title>
</head>
<script>
function pass() {
var secretword = passwordtext.value;
//This grabs the value element from the input named "passwordtext"
if (secretword=='uberpie') {
location = 'passwordpass.html';
}
//Ok, if they have the right password it sends them to a page
if else {
var back = history.back();
alert('Beep! You got the password wrong!');
location = back;
}
//This sends the user to the last page.
//I can also see a more complex system that writes
//a hidden value keeping the user out of the same page
//for the duration of their visit
</script>
<form>
<input name = "passwordtext" value = "Password"></input><a href = "javascript:pass();">Login</a></form>


It may seem complex at first, but if you think about it, it isn't too hard. Also, you could just copy the pass function to say, user(); and add a user thing. Of course, if you want a community site, go with PHP(or perl is pretty cool too).
Back to top
View user's profile Send private message
che100



Joined: 28 Feb 2004
Posts: 20
Location: Lebanon

PostPosted: Sat Feb 28, 2004 11:35 pm    Post subject: other scripts Reply with quote

here use this little javascript promt that i wrote
the password is calicali. read the script an understand it

<script language="Javascript">
<!--
var password = "calicali";
pwd = window.prompt("This is a restricted area. Please enter password","");
if(pwd != password)
{
alert("Invalid Password. Access denied.");
location.href="index.htm";
}
if (pwd == password)
{
alert("You have been granted access to page.")
}
// -->
</script>
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
RALLI//ART V3000



Joined: 29 Feb 2004
Posts: 3
Location: Wellington, New Zealand

PostPosted: Sun Feb 29, 2004 12:29 am    Post subject: Reply with quote

You can also use .htaccess & .htpasswd. both files should be put in the folder you wish to protect.

.htaccess should look like this:

AuthUserFile www.domain.com/folder/.htpasswd
AuthName Website_Name
AuthType Basic
<Limit GET>
require valid-user
</Limit>

.htpasswd should look like this:

username:encrypted password


Passwords can be encrypted here : http://homepages.paradise.net.nz/cgi-bin/pwcrypt.cgi

if you want to see this working, goto http://www.wellymodcars.co.nz and click on members area
_________________
Fraser Ray
Website Developor
Wellington Modified Car Club
Ph: 027 424 5504
Fax: 04 977 0813
Web: http://www.wellymodcars.co.nz
E-mail: fraser@wellymodcars.co.nz
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    GlobalWeb.com.ru Forum Index -> PHP All times are GMT
Page 1 of 1

 


Free Web Hosting, Commercial Web Hosting, PHP/mySQL Copyright © 2009
Free Scripts Directory | Free Software Downloads | Newsgroups Directory | Optel.net | Mirroraty | Cruised.net | Hardware Keylogger