PHP Login Script
Posted: Thu May 22, 2003 8:52 pm
G'day am new so if this a pain in the arse feel free to just email me weblinks where I can read stuff.
I am doing tutorials on how to create a simple login page - basically I want a navbar frame on the left that you can login to a form at the top. I want that login to basically go ok if you login I will change this frame (the initiall navbar) to another navbar that has other options.
I have created the navbar with a login form - thats sends userrname and password variables to a page call *****.php
that page looks like this.
<?php
session_start();
$db_user = 'kamvoices';
$db_pass = '*******';
$user_name = $_POST['user_name'];
$password = $_POST['password'];
//connect to the DB and select the "members" database
$connection = mysql_connect('kamvoicecs.com', $db_user, $db_pass) or die(mysql_error());
mysql_select_db('users', $connection) or die(mysql_error());
//set up the query
$query = "SELECT * FROM users
WHERE user_name='$user_name' AND password='$password'";
//run the query and get the number of affected rows
$result = mysql_query($query, $connection) or die('error making query');
$affected_rows = mysql_num_rows($result);
//if there's exactly one result, the user is validated. Otherwise, he's invalid
if($affected_rows == 1) {
function Redirect ($url) {
Header ("Welcome");
Header ("Location: http://www.kamvoices.com/logbar.htm" . $url);
exit;
}
else {
print 'not valid';
}
?>
<?php
//...snip...
if($affected_rows == 1) {
print 'validated';
//add the user to our session variables
$_SESSION['username'] = $user_name;
}
else {
print 'not valid';
}
?>
<?php
if(empty($_SESSION['username'])) {
die('An error has ocurred. It may be that you have not logged in, or that
your session has expired.
Please try <a href="login.php">logging in</a> again or contact the
<a href="mailto:dominic@standup.com">system administrator</a>');
}
?>
but it gives me these error's
- Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/httpd/html/kamvoices/Insertuser.php:6) in /home/httpd/html/kamvoices/Insertuser.php on line 7
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/httpd/html/kamvoices/Insertuser.php:6) in /home/httpd/html/kamvoices/Insertuser.php on line 7
Access denied for user: 'kamvoices@biglongemailaddressofmywebsitehost' to database 'users'
Anyone know whats going wrong?
I am doing tutorials on how to create a simple login page - basically I want a navbar frame on the left that you can login to a form at the top. I want that login to basically go ok if you login I will change this frame (the initiall navbar) to another navbar that has other options.
I have created the navbar with a login form - thats sends userrname and password variables to a page call *****.php
that page looks like this.
<?php
session_start();
$db_user = 'kamvoices';
$db_pass = '*******';
$user_name = $_POST['user_name'];
$password = $_POST['password'];
//connect to the DB and select the "members" database
$connection = mysql_connect('kamvoicecs.com', $db_user, $db_pass) or die(mysql_error());
mysql_select_db('users', $connection) or die(mysql_error());
//set up the query
$query = "SELECT * FROM users
WHERE user_name='$user_name' AND password='$password'";
//run the query and get the number of affected rows
$result = mysql_query($query, $connection) or die('error making query');
$affected_rows = mysql_num_rows($result);
//if there's exactly one result, the user is validated. Otherwise, he's invalid
if($affected_rows == 1) {
function Redirect ($url) {
Header ("Welcome");
Header ("Location: http://www.kamvoices.com/logbar.htm" . $url);
exit;
}
else {
print 'not valid';
}
?>
<?php
//...snip...
if($affected_rows == 1) {
print 'validated';
//add the user to our session variables
$_SESSION['username'] = $user_name;
}
else {
print 'not valid';
}
?>
<?php
if(empty($_SESSION['username'])) {
die('An error has ocurred. It may be that you have not logged in, or that
your session has expired.
Please try <a href="login.php">logging in</a> again or contact the
<a href="mailto:dominic@standup.com">system administrator</a>');
}
?>
but it gives me these error's
- Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/httpd/html/kamvoices/Insertuser.php:6) in /home/httpd/html/kamvoices/Insertuser.php on line 7
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/httpd/html/kamvoices/Insertuser.php:6) in /home/httpd/html/kamvoices/Insertuser.php on line 7
Access denied for user: 'kamvoices@biglongemailaddressofmywebsitehost' to database 'users'
Anyone know whats going wrong?