Current location: Hot Scripts Forums » Programming Languages » PHP » Need To Password Protect a Page For Multi-Users


Need To Password Protect a Page For Multi-Users

Reply
  #1 (permalink)  
Old 09-08-04, 06:05 PM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Need To Password Protect a Page For Multi-Users

I am wanting to password protect a page for multiple users to edit their profile in my mysql database. I have this code but it really is just for one user and password.
PHP Code:

<?


$login 
"user";
$password "password";

function 
error ($error_message) {
    echo 
$error_message."<BR>";
    exit;
}

if ( (!isset(
$PHP_AUTH_USER)) || ! (($PHP_AUTH_USER == $login) && ( $PHP_AUTH_PW == "$password)) ) {
    
header("WWW-Authenticate: Basic enter=\"Secured Area\"");
    
header("HTTP/1.0 401 Unauthorized");
    
error("You are not authorized!");
}

?>
Ok, my question is this... How can I code this to have the username and password to be checked against each individual member of my database? Each member of the database has an auto id, and I give them the freedom to choose a password when they sign up. So in the table the data is like...

member | id | password
member2 | id2 | password2
member3 | id3 | password3

Any ideas? I Know there is probably an easy way to do this but I am new at this stuff. Thanks!

PS. No need for Fort Knox like security either. Simple is fine.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-08-04, 06:42 PM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
this would work

Code:
<!-- login form -->
<form action="check.php" method="post>
Login<input type="text" name="login"><br>
Password<input type="password" name="password"><br>
<input type="submit" value="login">
PHP Code:

// check.php


$db "your db";
$host "yourhost"// default is normally localhost
$uid "login";
$pwd "password";

//simple clean and grab
$login mysql_escape_string($_POST['login']);
$password mysql_escape_string($_POST['password']);

//normal connection routine
$link mysql_connect($host,$uid,$pwd);
mysql_select_db($db);

//query db
$res mysql_query('SELECT id WHERE login = ' .$login.' and password = '.$password);

//check if there is a match
if(mysql_num_rows($res) > 0){
        
//grab the userid
        
$line mysql_fetch_array($res,MYSQL_NUM);
        
//set a session for later use
        
session_start();
        
$_SESSION['uid'] = $line[0];
        
         
// redirect them if you want
         
header('location:users.php');
}
else{  
// they screwed up
         
echo 'Login error';


any questions? I didn't run this I just typed it out quickly
__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 09-08-04, 08:24 PM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
PRoblem trying to get this script to work.. Look at http://www.quotingloans.com/include/mcPass.php
I know I have the database info correct (for obvious reasons the login info has been changed), but I am still getting this error...

Parse error: parse error, unexpected T_STRING in /home/quoting/public_html/include/mcPass.php on line 26

PHP Code:

  <?php 

// check.php 

$db "mydb"
$host "localhost"// default is normally localhost 
$uid "myusername"
$pwd "mypass"

//simple clean and grab 
$login mysql_escape_string($_POST['login']); 
$password mysql_escape_string($_POST['password']); 

//normal connection routine 
$link mysql_connect($host,$uid,$pwd); 
mysql_select_db($db); 

//query db 
$res mysql_query('SELECT id WHERE id = ' .$login.' and password = '.$password.'); 

//check if there is a match 
if(mysql_num_rows($res) > 0){ 
        //grab the userid 
        $line = mysql_fetch_array($res,MYSQL_NUM); 
        //set a session for later use 
        session_start(); 
        $_SESSION['
uid'] = $line[0]; 
         
         // redirect them if you want 
         header('
location:users.php'); 

else{  // they screwed up 
         echo '
Login error'; 

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 09-08-04, 09:34 PM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
Your not familiar with programming are you?

//query db
$res = mysql_query('SELECT id WHERE id = ' .$login.' and password = '.$password.');

just need to be changed to

//query db
$res = mysql_query('SELECT id WHERE id = ' .$login.' and password = '.$password);
__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 09-08-04, 10:16 PM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
I got the script to work somewhat but I do not see a login popup. IT only gives the scripted "login error" Here is what I have done. Any help is appreciated...
PHP Code:

<?php 

// check.php 

//normal connection routine 
$db=mysql_connect ("localhost""user""pass") or die ('I cannot connect to the database.');
mysql_select_db ("web_table",$db);

//simple clean and grab 
$login mysql_escape_string($_POST['id']); 
$password mysql_escape_string($_POST['password']); 


//query db 
$res mysql_query("SELECT id FROM realtors WHERE id='.$login.' and password='.$password.'"); 


//check if there is a match 
if (mysql_num_rows($res)<0){ 
        
//grab the userid 
        
$line mysql_fetch_array($res,MYSQL_NUM); 
        
//set a session for later use 
        
session_start(); 
        
$_SESSION['uid'] = $line['0']; 
         
         
// redirect them if you want 
         
header('location:users.php'); 

else{  
// they screwed up 
         
echo 'Login error'

?>

Last edited by cebuy; 09-08-04 at 10:19 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 09-08-04, 11:42 PM
nivek's Avatar
nivek nivek is offline
Newbie Coder
 
Join Date: Aug 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
you can go to bravenet and get a free password protected page easy.... I yous it on my site and it works good, you can also make othe people sighn up for it, so they can get there very own member page on your site. http://bravenet.com

please add your website to my site at http://linkfarm.TK
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 09-09-04, 12:58 AM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by infinitylimit
Your not familiar with programming are you?

//query db
$res = mysql_query('SELECT id WHERE id = ' .$login.' and password = '.$password.');

just need to be changed to

//query db
$res = mysql_query('SELECT id WHERE id = ' .$login.' and password = '.$password);
Sorry but that code just gets an error.

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/quoting/public_html/include/mcPass.php on line 18
Login error

I was under the impression that a proper mysql query requires a FROM statement aming the table as well.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 09-09-04, 01:12 AM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
I rather not. Thanks anyway!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 09-09-04, 08:57 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

$res mysql_query("SELECT id FROM realtors WHERE id='$login' and password='$password'") or die(mysql_error());

# OR #
$res mysql_query("SELECT id FROM realtors WHERE id='".$login."' and password='".$password."'") or die(mysql_error()); 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Classified Ads skipper23 Perl 3 11-22-05 03:22 AM
Directing link to password protected page brb PHP 2 06-15-04 05:10 AM
page browsing problem mivec PHP 3 04-17-04 04:43 AM
Quick Question for you php guru's Tokahashi PHP 3 04-09-04 01:00 PM
Classified Ads skipper23 Perl 2 12-30-03 04:43 AM


All times are GMT -5. The time now is 12:31 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.