JP128 Posted December 10, 2006 Share Posted December 10, 2006 I get the problem [code] PHP Warning: Cannot modify header information - headers already sent by (output started at /usr/htdocs/config.php:49) in /htdocs/config.php on line 84[/code]and thats it.. here is my current script.I showed what # the lines are... <-=-=-=- ## -=-=-=->[code]<?php################### Database Connect #############function dbConnect() { //Start of dbConnect mysql_connect("localhost", "*****", "********"); mysql_select_db("*****");} ################### User Auth ####################function userAuth() { //Connect to the database. dbConnect(); // <-=-=-=- THIS IS LINE 49 -=-=-=-> echo"Connected to database.<br>"; //Check to see if the cookies are set. if((isset($_COOKIE['username']))&&(isset($_COOKIE['password']))){ //beginning of 2 echo"The cookies are set.<br>"; //Set the username, and password values because the cookie is set. $username = $_COOKIE['username']; // <-=-=-=- THIS IS LINE 84 -=-=-=-> $password = $_COOKIE['password']; // <-=-=-=- THIS IS LINE 85 -=-=-=-> echo"Cookie values added to the variables."; //Check the cookie variables against the registry table. $checkCookie = mysql_query("SELECT username,password FROM `registry` WHERE username='$username' AND password=md5('$password')"); //Get the number of rows that $checkCookie looks up. $cookieRows = mysql_num_rows($checkCookie); if($cookieRows > 0){ echo"That information exists in database!<br>"; }else{ echo"That information does not exist in database!<br>"; //Show the login form because the cookie is invalid loginForm(); exit; } }else{ echo"That cookie doesn't exist. Checking to see if POST does...<br>"; //Check to see if the username, and password are set because the cookies aren't. if((isset($_POST['username']))&&(isset($_POST['password']))){ // if POST echo"Post is in fact set.<br>"; //Set the variables, because the POST is set. $username = $_POST['username']; $password = $_POST['password']; echo"Set the variables from POST<br>"; //Check the POST variables against the table Registry. $checkPost = mysql_query("SELECT username,password FROM registry WHERE username='$username' AND password=md5('$password')"); //Check on how many rows $checkPost looks up. $postRows = mysql_num_rows($checkPost); if($postRows > 0){ echo"Those POST variables are in the database.<br>"; setcookie("username",$username,time()+3600); setcookie("password",md5($password),time()+3600); echo"Set the cookie values...<br>"; }else{ echo"Showing Login form.<br>"; loginForm(); exit; } } } }[/code]I added all of the echo's in there to see how far it goes.I don't know what is going on, and why it doesn't work. If someone could take a look at it, that would be great... I also searched around alot and saw tons of people with the whitespace problem, but I don't think that that is my problem. Quote Link to comment Share on other sites More sharing options...
.josh Posted December 10, 2006 Share Posted December 10, 2006 you cannot have any html output before your setcookie function call. no echos, no blank lines above your php tags, no nothing. or you can look into [url=http://us2.php.net/ob_start]ob_start()[/url] if you need to have html output before it. Quote Link to comment Share on other sites More sharing options...
JP128 Posted December 10, 2006 Author Share Posted December 10, 2006 Ok, that is a new function to me... How would I use that in my script? Quote Link to comment Share on other sites More sharing options...
JP128 Posted December 10, 2006 Author Share Posted December 10, 2006 I have looked at php.net, and saw something like ob_start($buffer), but I don't know what that is... Could someone explain this function to me? Quote Link to comment Share on other sites More sharing options...
.josh Posted December 10, 2006 Share Posted December 10, 2006 at the top of your script put ob_start(); at the bottom put ob_end_flush(); Quote Link to comment Share on other sites More sharing options...
JP128 Posted December 10, 2006 Author Share Posted December 10, 2006 Now I get the error syntax error, unexpected T_STRING Quote Link to comment Share on other sites More sharing options...
.josh Posted December 10, 2006 Share Posted December 10, 2006 repost your code. Quote Link to comment Share on other sites More sharing options...
JP128 Posted December 10, 2006 Author Share Posted December 10, 2006 [CODE]<?phpfunction userAuth() {ob_start();//Connect to the database.dbConnect();echo"Connected to database.<br>";//Check to see if the cookies are set.if((isset($_COOKIE['username']))&&(isset($_COOKIE['password']))){ //beginning of 2echo"The cookies are set.<br>";//Set the username, and password values because the cookie is set.$username = $_COOKIE['username'];$password = $_COOKIE['password'];echo"Cookie values added to the variables.";//Check the cookie variables against the registry table.$checkCookie = mysql_query("SELECT username,password FROM `registry` WHERE username='$username' AND password=md5('$password')");Get the number of rows that $checkCookie looks up.$cookieRows = mysql_num_rows($checkCookie);if($cookieRows > 0){echo"That information exists in database!<br>";}else{echo"That information does not exist in database!<br>";//Show the login form because the cookie is invalidloginForm();exit;}}else{echo"That cookie doesn't exist. Checking to see if POST does...<br>";//Check to see if the username, and password are set because the cookies aren't.if((isset($_POST['username']))&&(isset($_POST['password']))){ // if POSTecho"Post is in fact set.<br>";//Set the variables, because the POST is set.$username = $_POST['username'];$password = $_POST['password'];echo"Set the variables from POST<br>";//Check the POST variables against the table Registry.$checkPost = mysql_query("SELECT username,password FROM registry WHERE username='$username' AND password=md5('$password')");//Check on how many rows $checkPost looks up.$postRows = mysql_num_rows($checkPost);if($postRows > 0){$username = $_POST['username'];$password = $_POST['password'];setcookie("username",$username,time()+3600);setcookie("password",md5($password),time()+3600);echo"Those POST variables are in the database.<br>";echo"Set the cookie values...<br>";}else{echo"Showing Login form.<br>";loginForm();exit;}}}ob_end_flush();}?>[/CODE] Quote Link to comment Share on other sites More sharing options...
.josh Posted December 10, 2006 Share Posted December 10, 2006 "Get the number of rows that $checkCookie looks up." has no // before it Quote Link to comment Share on other sites More sharing options...
JP128 Posted December 10, 2006 Author Share Posted December 10, 2006 ok, but I still get the header problem. Quote Link to comment Share on other sites More sharing options...
.josh Posted December 10, 2006 Share Posted December 10, 2006 okay, i see that you have ob_start() and ob_end_flush() inside a function, which means that the script you have provided is part of a larger script. ob_start() has to be at the beginning of the entire script and ob_end_flush() has to be at the end of the entire script. Quote Link to comment Share on other sites More sharing options...
JP128 Posted December 10, 2006 Author Share Posted December 10, 2006 Still the same problem. I put it at the beginning of the file. Quote Link to comment Share on other sites More sharing options...
.josh Posted December 10, 2006 Share Posted December 10, 2006 is your file being included into some other file? you need to put it in [i]that[/i] file. The point is, it needs to be the very first thing php sees. Quote Link to comment Share on other sites More sharing options...
JP128 Posted December 10, 2006 Author Share Posted December 10, 2006 alright, i see. I no longer get the error... thanks. Now I just need to make sure the password is put into the db correctly. Quote Link to comment 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.