| | |
php help needed for login
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2004
Posts: 22
Reputation:
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:
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:
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!
![]() |
Similar Threads
- Simple ASP.Net Login Page using C# (C#)
- login at youtube using cURL and php ? (PHP)
- PHP Help needed badly (PHP)
- problems with sessions and login.php (PHP)
Other Threads in the PHP Forum
- Previous Thread: the form cant remember me ?????
- Next Thread: help for connection to mysql
| Thread Tools | Search this Thread |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue problem query radio random recourse recursion regex remote script search seo server sessions sms source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube





