Forum Moderators: coopster
You certainly could use the same file. You're going to have to learn some scripting though if you intend to use a login system to secure pages. What do you mean you can't do it yourself? Plenty of folks have learned how right here on WebmasterWorld. A quick search on this site will turn up plenty of resources, including links to tutorials, code samples, etc. Why not give it a whirl?
***** BEGIN CODE ******\/
<?php
// File Name: login.php
// Check to see if $PHP_AUTH_USER already contains info
$host = "localhost";
$user = "ENTER_YOUR_dB_USER_NAME_HERE";
$pass = "AND_YOUR_PASSWORD_HERE";
$db = "DATABASE_NAME_HERE";
$utable = "TABLE_NAME_HERE";
mysql_connect($host,$user,$pass) or die("Unable to connect to database");
@mysql_select_db("$db") or die("Unable to select database $db");
if (!isset($PHP_AUTH_USER)) {
// If empty, send header causing dialog box to appear
header('WWW-Authenticate: Basic realm="SOME FRIENDLY NAME HERE"');
header('HTTP/1.0 401 Unauthorized');
exit;
} else if (isset($PHP_AUTH_USER)) {
// Formulate the query
$sql = "SELECT * FROM $utable WHERE usr_name='$PHP_AUTH_USER' and usr_pwd='$PHP_AUTH_PW'";
// Execute the query and put results in $result
$result = mysql_query($sql);
// Get number of rows in $result. 0 if invalid, 1 if valid.
$num = mysql_numrows($result);
if ($num!= "0") {
header("Location: secure.page.name.php");
exit;
} else {
header('WWW-Authenticate: Basic realm="ANY MESSAGE YOU WANT THE WINDOW TO SAY HERE"');
header('HTTP/1.0 401 Unauthorized');
echo 'Authorization Required.';
exit;
}
}
?>
***** END CODE ******^
Remember that has to be before any HTML coding on your PHP pages.
$sql = "SELECT * FROM $utable WHERE usr_name='$PHP_AUTH_USER' and usr_pwd='$PHP_AUTH_PW'";
usr_name will need to be the column name in the phpbb table for users where the user name is stored and the same thing for usr_pwd
Italianmob This is nice and kind of you
However I remember the time I had almost no ideas on what I wanted to achieve
Not sure I still do :)
Many members such as Coopster helped me out by suggesting, letting me learn from my errors and pointing me to the correct route
You will seldom see full scripts posted (although I remember I have done it once - Mea Culpa! – )
In order for Supermanjnk to get something out of it
Would you be kind enough in adding a few in depth comments and reason why...
Your existing comments are very meaningful if you have already a basic knowledge
Please remember that Supermanjnk mentioned that he was pretty much inexperimented
By advance thank you
Hope I did not offend you
We may all learn from precise comments
Best regards
Henry
But each person has their own style of learning.
But if he wants some good books on PHP I would suggest the following two books.
PHP Programming by WROX
PHP and MySQL Web Development by SAMS
those are two excellent books if you a really serious about learning dynamic web content with PHP. Especially the later.
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/youth22/public_html/auth.php on line 32
Warning: Cannot modify header information - headers already sent by (output started at /home/youth22/public_html/auth.php:32) in /home/youth22/public_html/auth.php on line 35
$sql = "SELECT * FROM $utable WHERE username='$PHP_AUTH_USER' and user_password='$PHP_AUTH_PW'";
// Execute the query and put results in $result
$result = mysql_query($sql);
// Get number of rows in $result. 0 if invalid, 1 if valid.
$num = mysql_numrows($result);
if ($num!= "0") {
header("Location: secure.page.name.php");
exit;
Is the code i have here. Something is wrong with this line:
$num = mysql_numrows($result);
I've tried changing it to mysql_num_rows but i still get the same result
ADDED:
I put in a die statement so it would tell me what the error is this is what i get back now:
1142: select command denied to user: 'youth22_Jasonk@localhost' for table 'phpbb_users'
That user has full access to the database, so I have no clue why the select command is being denied