Hey,
I was just wanting a simple user-authentication system. Any good tutorials out there?
Thanks
Hey,
I was just wanting a simple user-authentication system. Any good tutorials out there?
Thanks
Best bet is to look around in this forum for scripts and try different things that you think might work for your application.
I find all kinds of great code solutions here.
Both of you, thanks.
Here's the code I am using for login:
<?php
session_start();
// dBase file
include "conf.php";
if ($_GET["op"] == "login")
{
if (!$_POST["username"] || !$_POST["password"])
{
die("You need to supply a username and password.");
}
// Create query
$q = "SELECT * FROM `dbUsers` "
."WHERE `username`='".$_POST["username"]."' "
."AND `password`=PASSWORD('".$_POST["password"]."') "
."LIMIT 1";
// Run query
$r = mysql_query($q);
if ( $obj = @mysql_fetch_object($r) )
{
// Login O.K., create session variables
$_SESSION["valid_id"] = $obj->id;
$_SESSION["valid_user"] = $_POST["username"];
$_SESSION["valid_time"] = time();
// Redirect to member page
Header("Location: admin.php");
}
else
{
// Login not successful
die("Sorry, could not log you in. Wrong login information.");
}
}
else
{
echo "<form action=\"?op=login\" method=\"POST\">";
echo "Username: <input name=\"username\" size=\"15\"><br />";
echo "Password: <input name=\"password\" size=\"8\"><br />";
echo "<input type=\"submit\" value=\"Login\">";
echo "</form>";
}
?>
This is on login.php, when I go to login.php, I get this error:
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/marshall/public_html/login.php:15) in /home/marshall/public_html/login.php on line 116
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/marshall/public_html/login.php:15) in /home/marshall/public_html/login.php on line 116
What did I do wrong?
Try moving the session_start() up to line one. Is the <? tag on the very first line? No white space at all?
Make sure the first line is:
<?php session_start() ;
Actually, what I had done is had that code in my HTML.
Like
HTML
CODE
HTML
How should I break the code up for it to work properly...
The very very very very very very top line of your HTML document needs to be <?php session_start(); ?>
Even before the doc type. If your IDE allows for line numbers, line number 1 is the session_start().
Other than that, it doesn't matter where the rest of my PHP goes?
Okay,
I put session_start on the very first line and it loads up without errors. When trying to login here's what happens:
Right Login and Right Password
It displays, "Sorry, could not log you in. Wrong login information." This is wrong, I am 100% I entered the correct password and username, actually tried it several times.
Right Login and Wrong Password
It displays, "Sorry, could not log you in. Wrong login information." like it should.
No Login or Password
It displays, "You need to supply a username and password.." like it should.
So, did I do wrong in the code?
I've tried everything I could think of, hopefully someone will be nice enough to help me!
This line seems odd...
if ( $obj = @mysql_fetch_object($r) )
Try changing it to
while( $obj = @mysql_fetch_object($r) )
Steveo,
Thanks. If I change that 'if' to 'while' then what happens to the 'else' statement just below it?