Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what is causing the "headers already exist" message

Status
Not open for further replies.

bopritchard

Programmer
Jan 27, 2003
199
US
what in this file is causing the "headers already exist" message?


contents of login.php
<?
include ("config.inc.php");
$username=$_POST['username'];
$password=$_POST['password'];

mysql_connect( "$hostname", "$dbusername", "$dbpassword")
or die ("Unable to connect to server.");
mysql_select_db("$db_name")
or die ("Unable to select database.");
$sql = "SELECT *
FROM users
WHERE username='$username' and password='$password'";
$result = mysql_query($sql)
or die ("Unable to get results.");
$num = mysql_numrows($result)
or die ("You're not authorized to be here. If you feel you have recieved this
message in error, please contact the <a
href=\"mailto:bopritchard@mindspring.com\">webmaster</a>");
if ($num == 1) {
$row = mysql_fetch_row ($result);
$id=$row[0];
session_start();
$_SESSION['userid'] = 'crap';
$_SESSION['otauth'] = 'no';
print "$id";
echo "Your username is $username</p>";
}
?>

contents of config.inc.php
<?php
$dbusername = "asdfasdfasdf"; //Database Username
$dbpassword = "adfasdfsdaf"; //Database password
$db_name = "asdfasdfsadf"; //Database name
$hostname= "asdfasdfasdf";
?>
 
Is your message "headers already sent"? Then check that there is no white space before the <? in either file and that there is none after ?> in config. Also check that you aren't echoing anything before the session_start().

--Chessbot

"Violence is the last refuge of the incompetent." -- Asimov, Foundation
 
config.inc.php page:

<?
//enter the username and password that conncts you to the database "localhost is normally ok to keep as is"
$db = @mysql_connect( "localhost", "user", "password")
or die ("Unable to connect to server.");

//enter the name of the database that you are attempting to connect 2
@mysql_select_db("name_of_database", $db)
or die ("Unable to select database.");
?>



page 2:

<?php
//when you include now to the connection you only have to make this connection one time and it reads easier
include ("conn.php");

$username = $_POST['username'];
$password = $_POST['password'];

/*consider making the usernames unique instead of having to type the username
and password to login, there should not be 2 users with the same username anyways */
$result = @mysql_query("SELECT *
FROM users
WHERE username = '$username'");

//make sure that you always look at your code right for example: mysql_num_rows not mysql_numrows
$num = @mysql_num_rows($result);

if(!$num){
echo "You're not authorized to be here. If you feel you have recieved this message in error,
please contact the <a href='mailto:bopritchard@mindspring.com'>webmaster</a>";
}else{
if ($num == 1) {
$row = @mysql_fetch_row ($result);
$id = $row[0];
session_start();
$_SESSION['userid'] = 'crap';
$_SESSION['otauth'] = 'no';
//also stay consistant with your choice of print or echo although it still works it reads better
echo $id;
echo "Your username is $username</p>";
}
}
?>

good luck with your project

Nothing is hard when you realy want to learn it.

Max
 
make sure that you add the: <?php at the start of the code

<?php
//enter the username and password that conncts you to the database "localhost is normally ok to keep as is"
$db = @mysql_connect( "localhost", "user", "password")
or die ("Unable to connect to server.");

//enter the name of the database that you are attempting to connect 2
@mysql_select_db("name_of_database", $db)
or die ("Unable to select database.");
?>

Nothing is hard when you realy want to learn it.

Max
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top