nander Posted December 7, 2011 Share Posted December 7, 2011 Hello I am getting this error in my script. Can anyone help? Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb25b/b904/ipg.votpservicescom/listing15.8.php:12) in /hermes/bosweb25b/b904/ipg.votpservicescom/listing15.8.php on line 39 if ((!$_POST[username]) || (!$_POST[password])) { header("Location: listing15.7.php"); exit; } //connect to server and select database $link = mysql_connect('servicescom.ipagemysql.com', 'ssap', 'pass'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_select_db(formlogin); //create and issue the query $sql = "select f_name, l_name from auth_users where username = '$_POST[username]' AND password = password('$_POST[password]')"; $result = mysql_query($sql, $link) or die(mysql_error()); //get the number of rows in the result set; should be 1 if a match if (mysql_num_rows($result) == 1) { //if authorized, get the values of f_name l_name $f_name = mysql_result($result, 0, 'f_name'); $l_name = mysql_result($result, 0, 'l_name'); //set authorization cookie setcookie("auth", "1", 0, "/", "votpservices.com", 0); //prepare message for printing, and user menu $msg = "<P>$f_name $l_name is authorized!</p>"; $msg .= "<P>Authorized Users' Menu:"; $msg .= "<ul><li><a href=\"listing15.8.php\">secret page</a></ul>"; } else { //redirect back to login form if not authorized header("Location: listing15.7.php"); exit; } ?> <html> <head> <title>Listing 15.8 User Login</title> </head> <body> <?php print "$msg"; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/252712-header-error/ Share on other sites More sharing options...
msaz87 Posted December 7, 2011 Share Posted December 7, 2011 Your code is outputting a value before it reaches the header, which causes it to fail. Identify what it's spitting out beforehand. Quote Link to comment https://forums.phpfreaks.com/topic/252712-header-error/#findComment-1295535 Share on other sites More sharing options...
requinix Posted December 7, 2011 Share Posted December 7, 2011 Did you see the HEADER ERRORS - READ HERE BEFORE POSTING THEM sticky? Quote Link to comment https://forums.phpfreaks.com/topic/252712-header-error/#findComment-1295538 Share on other sites More sharing options...
Pikachu2000 Posted December 7, 2011 Share Posted December 7, 2011 There's a sticky topic: HEADER ERRORS - READ HERE BEFORE POSTING THEM Quote Link to comment https://forums.phpfreaks.com/topic/252712-header-error/#findComment-1295539 Share on other sites More sharing options...
nander Posted December 8, 2011 Author Share Posted December 8, 2011 The sticky topic HEADER ERRORS - READ HERE BEFORE POSTING THEM was a bit confusing? I think I dont it correctly but still getting the same error? Quote Link to comment https://forums.phpfreaks.com/topic/252712-header-error/#findComment-1295589 Share on other sites More sharing options...
nander Posted December 8, 2011 Author Share Posted December 8, 2011 Meant to say I think I was doing it correctly. msaz87 how can I find what the script is outputting? Quote Link to comment https://forums.phpfreaks.com/topic/252712-header-error/#findComment-1295591 Share on other sites More sharing options...
KevinM1 Posted December 8, 2011 Share Posted December 8, 2011 Post your current code. And be sure to put it between either or tags. Quote Link to comment https://forums.phpfreaks.com/topic/252712-header-error/#findComment-1295593 Share on other sites More sharing options...
nander Posted December 8, 2011 Author Share Posted December 8, 2011 <?php //check for required fields from the form if ((!$_POST[username]) || (!$_POST[password])) { header("Location: listing15.7.php"); exit; } //connect to server and select database $link = mysql_connect('votpservicescom.ipagemysql.com', 'logindb', 'password'); if (!$link) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_select_db(formslogin); //create and issue the query $sql = "select f_name, l_name from auth_users where username = '$_POST[username]' AND password = password('$_POST[password]')"; $result = mysql_query($sql, $link) or die(mysql_error()); //get the number of rows in the result set; should be 1 if a match if (mysql_num_rows($result) == 1) { //if authorized, get the values of f_name l_name $f_name = mysql_result($result, 0, 'f_name'); $l_name = mysql_result($result, 0, 'l_name'); //set authorization cookie setcookie("auth", "1", "0", "/", "votpservices.com", 0); //prepare message for printing, and user menu $msg = "<P>$f_name $l_name is authorized!</p>"; $msg .= "<P>Authorized Users' Menu:"; $msg .= "<ul><li><a href=\"listing15.8.php\">secret page</a></ul>"; } else { //redirect back to login form if not authorized header("Location: listing15.7.php"); exit; } ?> <html> <head> <title>Listing 15.8 User Login</title> </head> <body> <?php print "$msg"; ?> </body> </html> MOD EDIT: . . . tags added. Quote Link to comment https://forums.phpfreaks.com/topic/252712-header-error/#findComment-1295597 Share on other sites More sharing options...
Pikachu2000 Posted December 8, 2011 Share Posted December 8, 2011 Post your current code. And be sure to put it between either . . . or . . . tags. Quote Link to comment https://forums.phpfreaks.com/topic/252712-header-error/#findComment-1295621 Share on other sites More sharing options...
Pikachu2000 Posted December 8, 2011 Share Posted December 8, 2011 You're sending output to the browser with echo 'Connected successfully'; Remove it and try it again. Quote Link to comment https://forums.phpfreaks.com/topic/252712-header-error/#findComment-1295623 Share on other sites More sharing options...
nander Posted December 8, 2011 Author Share Posted December 8, 2011 Pikachu2000 tried that and I get the same error? I think it has something to do with the second header because I change the file of the second header and it takes me to that page. Quote Link to comment https://forums.phpfreaks.com/topic/252712-header-error/#findComment-1295856 Share on other sites More sharing options...
Pikachu2000 Posted December 8, 2011 Share Posted December 8, 2011 Post the error message you're currently getting, and the revised code. Quote Link to comment https://forums.phpfreaks.com/topic/252712-header-error/#findComment-1295907 Share on other sites More sharing options...
nander Posted December 8, 2011 Author Share Posted December 8, 2011 Pikachu2000 Ok here is my code now its ridirecting me to the 2nd header page instead of showing me the successfull login page? <?php ob_start() ; //check for required fields from the form if ((!$_POST[username]) || (!$_POST[password])) { header("Location: listing15.7.php"); exit; } //connect to server and select database $link = mysql_connect('servicescom.ipagemysql.com', 'enter', 'password'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db(formlogin); //create and issue the query $sql = 'SELECT `auth_users` . `f_name` , `auth_users` . `l_name` ' . ' FROM auth_users ' . ' LIMIT 0, 30 '; $result = mysql_query($sql, $link) or die(mysql_error()); //get the number of rows in the result set; should be 1 if a match if (mysql_num_rows($result) == 1) { //if authorized, get the values of f_name l_name $f_name = mysql_result($result, 0, 'f_name'); $l_name = mysql_result($result, 0, 'l_name'); //set authorization cookie setcookie("auth", "1", 0, "/", "services.com", 0); //prepare message for printing, and user menu $msg = "<P>$f_name $l_name is authorized!</p>"; $msg .= "<P>Authorized Users' Menu:"; $msg .= "<ul><li><a href=\"listing15.8.php\">secret page</a></ul>"; } else { //redirect back to login form if not authorized header("Location: topiclist.php"); exit; } ob_end_flush(); ?> <html> <head> <title>Listing 15.8 User Login</title> </head> <body> <?php print "$msg";?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/252712-header-error/#findComment-1296003 Share on other sites More sharing options...
Drummin Posted December 8, 2011 Share Posted December 8, 2011 Might I suggest $sql = "SELECT `auth_users`,`f_name`,`l_name` FROM auth_users LIMIT 0, 30"; Quote Link to comment https://forums.phpfreaks.com/topic/252712-header-error/#findComment-1296007 Share on other sites More sharing options...
nander Posted December 9, 2011 Author Share Posted December 9, 2011 Drummin No go same result. Quote Link to comment https://forums.phpfreaks.com/topic/252712-header-error/#findComment-1296012 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.