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?
PHP Login Script
Moderator: General Moderators
-
Dominic
- Forum Newbie
- Posts: 1
- Joined: Thu May 22, 2003 8:52 pm
- Location: www.kamvoices.com
- metalhardscripts
- Forum Newbie
- Posts: 8
- Joined: Thu May 22, 2003 8:29 pm
- Location: Michigan
- Contact:
hmmmm
looks like the mysql is messing up to me try changing only the mysql parts and see if it does any good if not let me know and i will write ya a new one
The errors you are getting are caused by your script sending something (characters, new lines, spaces) to the browser before the header() function is called. Sending anything to the browser before outputting the headers is illegal. Make sure you don't have any ?><? with any whitespace in between before the header function is called.
- scorphus
- Forum Regular
- Posts: 589
- Joined: Fri May 09, 2003 11:53 pm
- Location: Belo Horizonte, Brazil
- Contact:
Also take a look to these topics:
Before Post Read: Warning: Cannot add header information
Before Post Read: Sessions with a Minor in User Logins
And:
Before Post Read: General Posting Guidelines
Before Post Read: Concerning Passing Variables in PHP 4.2+
Before Post Read: Frames, JavaScript, and PHP Overview
They are all very helpful.
Regards,
Scorphus.
Before Post Read: Warning: Cannot add header information
Before Post Read: Sessions with a Minor in User Logins
And:
Before Post Read: General Posting Guidelines
Before Post Read: Concerning Passing Variables in PHP 4.2+
Before Post Read: Frames, JavaScript, and PHP Overview
They are all very helpful.
Regards,
Scorphus.