•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,520 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,814 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 3284 | Replies: 5
![]() |
| |
•
•
Join Date: Jun 2004
Posts: 22
Reputation:
Rep Power: 5
Solved Threads: 0
I highly recommend the free version of Cookie Password Protection. I use it on my site to protect certain database interfaces I don't want people getting into.
•
•
Join Date: Aug 2004
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
hey, if u find someone that knows how to do login php script, email me. my friend is setting up an rpg. having a login screen would be kool where he would not have to put u in himself. when putting in the login name, i would like to go straight to my member stats kinda like yahoo for the mail accont.
ill post the site when i talk to him next.
if anyone else can help me and him out, email me and ill give him ur email address and he'll email u about his site.
ill post the site when i talk to him next.
if anyone else can help me and him out, email me and ill give him ur email address and he'll email u about his site.
•
•
Join Date: Aug 2004
Posts: 12
Reputation:
Rep Power: 5
Solved Threads: 0
How about using PHP sessions like this:
<?php
if (!isset($PHP_AUTH_USER) || !isset($PHP_AUTH_PW)) {
//If the PHP session variables aren't set, ask for name and password
header('WWW-Authenticate: Basic realm="Authorized Users Only"');
header('HTTP/1.0 401 Unauthorized');
exit;
} else if (isset($PHP_AUTH_USER) && isset($PHP_AUTH_PW)) {
//If the variables are set, check the username and password against a //database.
$conn = pg_Connect("host=localhost dbname=[dbname] port=[portnumber]");
$result = pg_Exec($conn,
"SELECT *
FROM [table]
WHERE username='$PHP_AUTH_USER' AND
password='$PHP_AUTH_PW';");
$num = pg_NumRows($result);
$i = 0;
//If the user is authenticated against the database, echo the html code for //the page you want them to see
if ($num != 0) {
echo "<HTML> ...... </HTML>"
}
}
?>
Use this configuration for any web page on your site that should have restricted access, then rename those files with a .php extension. In this example the connection is to a PostgreSQL database on my linux server, you may need a different connection string/method for your needs, but this works great otherwise. Once a user provides their login information they can immediately access any of the pages with the php code. Their login wont be lost until they close their browser, or you could give them a logout option that would reset the user and password variables. I found the original tutorial on this at this address: http://webmonkey.wired.com/webmonkey...tw=programming
Hope this helps!
<?php
if (!isset($PHP_AUTH_USER) || !isset($PHP_AUTH_PW)) {
//If the PHP session variables aren't set, ask for name and password
header('WWW-Authenticate: Basic realm="Authorized Users Only"');
header('HTTP/1.0 401 Unauthorized');
exit;
} else if (isset($PHP_AUTH_USER) && isset($PHP_AUTH_PW)) {
//If the variables are set, check the username and password against a //database.
$conn = pg_Connect("host=localhost dbname=[dbname] port=[portnumber]");
$result = pg_Exec($conn,
"SELECT *
FROM [table]
WHERE username='$PHP_AUTH_USER' AND
password='$PHP_AUTH_PW';");
$num = pg_NumRows($result);
$i = 0;
//If the user is authenticated against the database, echo the html code for //the page you want them to see
if ($num != 0) {
echo "<HTML> ...... </HTML>"
}
}
?>
Use this configuration for any web page on your site that should have restricted access, then rename those files with a .php extension. In this example the connection is to a PostgreSQL database on my linux server, you may need a different connection string/method for your needs, but this works great otherwise. Once a user provides their login information they can immediately access any of the pages with the php code. Their login wont be lost until they close their browser, or you could give them a logout option that would reset the user and password variables. I found the original tutorial on this at this address: http://webmonkey.wired.com/webmonkey...tw=programming
Hope this helps!
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- PHP Programmer needed on contract basis (Web Development Job Offers)
- PHP / IIS / Integrated login w/ home directories (PHP)
- problems with sessions and login.php (PHP)
- PHP Query, Make users login before accessing a movie? (PHP)
- how to make member expire after so many days with php script (PHP)
- PHP coder needed for online game (Web Development Job Offers)
Other Threads in the PHP Forum
- Previous Thread: the form cant remember me ?????
- Next Thread: help for connection to mysql


Hybrid Mode