PC Nerd Posted January 18, 2007 Share Posted January 18, 2007 ive tried to create some cookies, but im getting the erro that says header information cannot be sent. the output starts on the "<?php" which is realy strangeim just wondering is cookies are actually header information, or if this is a strang error Quote Link to comment https://forums.phpfreaks.com/topic/34730-are-cookies-header-information/ Share on other sites More sharing options...
Orio Posted January 18, 2007 Share Posted January 18, 2007 Cookie are transfered with the headers.You probably have a line break or a white space before the opening "<?php" that is causing the error.Orio. Quote Link to comment https://forums.phpfreaks.com/topic/34730-are-cookies-header-information/#findComment-163663 Share on other sites More sharing options...
taith Posted January 18, 2007 Share Posted January 18, 2007 technically... nohowever...headers are always sent along whenever you click on a link... but cookies and sessions exsist only within the browser/computer... the first thing php does is grabs the headers, then it goes through the code systematically. when php comes to a cookie/session_start, it goes to the browser and grabs the requested information. now if any information has already been sent to the browser, php cant request more information and errors out. hence them errors :-) Quote Link to comment https://forums.phpfreaks.com/topic/34730-are-cookies-header-information/#findComment-163666 Share on other sites More sharing options...
hvle Posted January 18, 2007 Share Posted January 18, 2007 I disagree with Taith,PHP CAN NOT go to the browser and grab the requested information even if it want to. Remember, webserver is between browser and PHP, therefore, PHP have nothing directly to do with browser.Cookies sent to web server by browser when user visit a page. Cookies data is stored in request header from browser.It is the protocol restriction that cookie must be sent before any output to browser, include html and head tags. In PHP, you need to place <?php at the first line and first character of the php file.Then in side the php script, do not out put anything before the setcookie line. Quote Link to comment https://forums.phpfreaks.com/topic/34730-are-cookies-header-information/#findComment-163742 Share on other sites More sharing options...
taith Posted January 18, 2007 Share Posted January 18, 2007 sessions are stored within the browser... that is a fact...and cookies are stored in the computers temp files... thats a fact...so... if php cant get to the browser or to the temp files... how?if sessions were sent along with the headers... why do you need to session_start()?and if cookies were sent along with the headers? why do they error out(headers sent error) when you try to get them after outputing data? Quote Link to comment https://forums.phpfreaks.com/topic/34730-are-cookies-header-information/#findComment-163750 Share on other sites More sharing options...
hvle Posted January 18, 2007 Share Posted January 18, 2007 session id stored as a cookie in your browser, but the session data (variables and such) are stored on the server. cookies data is stored in a cookie file depend on each browser. Each browser has their own way to store cookies.but yes, cookies are stored within browser.say you type www.google.com, the first thing browser do is prepare a header, including prepare any cookie data related to google.com and send to google.com. That is only way PHP can read your cookie.When browser want to set a cookie data, it send to the browser, again, as a header. But because of protocol restriction, this header can not be send after any out put data from server to browser. Quote Link to comment https://forums.phpfreaks.com/topic/34730-are-cookies-header-information/#findComment-163763 Share on other sites More sharing options...
PC Nerd Posted January 19, 2007 Author Share Posted January 19, 2007 this is my code: the login script:[code]<?php include("inc_files/B_A-Create_cookies.inc");?><html><head><link rel="stylesheet" type="text/css" href="B_A-CSS.css"><title>Battle Ages Login</title><?phpinclude("inc_files/Database_link.inc");if(empty($_POST['User_Name']) || empty($_POST['Password']) || empty($_POST['Valid'])) { $Error1 = "True"; $Error = "True";}require("inc_files/Login_Pics.inc");$img_post_valid = $_POST['IMG_Valid'];$Image_Validate = $IMAGES["B_A-Login_$img_post_valid"];if($_POST['IMG_Valid'] != $Image_Validate) { $Error2 = "True"; $Error = "True";}$SQL_Login = "SELECT User_Name, `Password` FROM General_Stats WHERE User_Name = '".$_POST['User_Name']."'";$Login_Query = mysqli_query($DB_Server, $SQL_Login);if(empty($Login_Query)) { $Error3 = "True"; $Error = "True";}$DB_Login = mysqli_fetch_array($Login_Query);if(empty($DB_Login)) { $Error4 = "True"; $Error = "True";}if(empty($Error)) { include("inc_files/B_A-Create_Cookies.inc");}#echo "<form name = 'Login_Relocation' action = 'B_A-Base.php' method = 'POST'>\n";#echo "<input type = 'button' name = 'relocation' value = 'Play Battle-Ages'>\n";#echo "</form>";echo "<a href = 'B_A-Base.php' alt = 'Base'>Player Battle-Ages</a>\n";if($Error1 = "True") { die("ERROR 1 You have not filled in the log in fields correctly. Click <a href = 'B_A-Home.php' alt = 'Home'>here</a> to return to the Home Page.");}if($Error2 = "True") { die("ERROR 2 You did not type in the correct validation image. Click <a href = 'B_A-Home.php' alt = 'Home'>here</a> to return to the Home Page.");}if($Error3 = "True") { die("ERROR 3 There was an error in the Database. You have not been logged in. Click <a href = 'B_A-Home.php' alt = 'Home'>here</a> to return to the Home Page.");#.mysqli_error($Login_Query));}if($Error4 = "True") { die("ERROR 4 There was an error in the Database. You have not been logged in. Click <a href = 'B_A-Home.php' alt = 'Home'>here</a> to return to the Home Page.");#.mysqli_error($DB_Login));}?></head><body><table><thead> <td class = 'left'> <img src="Graphics\Small_Logo.GIF" alt="Logo" width = '75%' hight = '75%' align = 'left'> </td> <td class = "centre"> </td> <td class = 'right'> <img src="Graphics\Small_Logo.GIF" alt="Logo" width = '75%' hight = '75%' align = 'right'> </td></thead><tbody><tr><td class = "left"><?php include("inc_files/B_A-Ext_Side_Links.inc"); ?></td><td class = 'centre'></td><td class = 'right'></td></tr></tbody></table></body></html>[/code]this is the create cookies include file:[code]<?php$User_Name = $_POST['User_Name'];$Logged_In = "YES";$Active = "Yes";setcookie("User_Name", $User_Name, strtotime('+ 30 minutes'));setcookie("Logged_In", $Logged_In, strtotime('+ 30 minutes'));setcookie("Active", $Active, strtotime('+ 30 minutes'));#setcookie(G_Points, $Cookie_Create['G_Points'], strtotime('+ 30 minutes'));#setcookie(Points, $Cookie_Create['Points'], strtotime('+ 30 minutes'));#setcookie(Moves, $Cookie_Create['Moves'], strtotime('+ 30 minutes'));#setcookie(Resources, $Cookie_Create['Resources'], strtotime('+ 30 minutes'));#setcookie(Attack, $Cookie_Create['Attack'], strtotime('+ 30 minutes'));#etcookie(Power, $Cookie_Create['Power'], strtotime('+ 30 minutes'));#setcookie(Logged_In, 'YES', strtotime('+ 30 minutes')););#$_COOKIE[User]#$_COOKIE[Logged_In]#$_COOKIE[S_Points]#$_COOKIE[A_Points]#$_COOKIE[G_Points]#$_COOKIE[Points]#$_COOKIE[Moves]#$_COOKIE[Resources]#$_COOKIE[Attack]#$_COOKIE[Defense]#$_COOKIE[Power]?>[/code]im just stumped on how to fix this Quote Link to comment https://forums.phpfreaks.com/topic/34730-are-cookies-header-information/#findComment-164203 Share on other sites More sharing options...
whitelion Posted January 19, 2007 Share Posted January 19, 2007 If you want to fix it easyly.I suggest you should using ob_start() function.It will help you fix your problem.[CODE]<?ob_start();//your informationob_end_clean();// when you want to use header functionob_end_flush(); //To the end of page?>[/CODE] Quote Link to comment https://forums.phpfreaks.com/topic/34730-are-cookies-header-information/#findComment-164204 Share on other sites More sharing options...
Crimpage Posted January 19, 2007 Share Posted January 19, 2007 Have a look at View Source in your web browser and see what is before that error message. It will show you whether it is a blank line that has been sent or <HTML><HEAD> tags etc... Quote Link to comment https://forums.phpfreaks.com/topic/34730-are-cookies-header-information/#findComment-164212 Share on other sites More sharing options...
PC Nerd Posted January 19, 2007 Author Share Posted January 19, 2007 ok, this is the specific code from the "veiw source" int he internet browser.but im confused becauase the html and head tages are all there before the error, but the erro generated is on the first line of the entire page.any more suggestions ??thanks for all you help, PC Nerd Quote Link to comment https://forums.phpfreaks.com/topic/34730-are-cookies-header-information/#findComment-164251 Share on other sites More sharing options...
Crimpage Posted January 19, 2007 Share Posted January 19, 2007 Actually, you include it on the first line, but you also include it again further down at:if(empty($Error)) { include("inc_files/B_A-Create_Cookies.inc");}change it to:if(empty($Error)) { echo "showing this"; include("inc_files/B_A-Create_Cookies.inc");}And see if it prints that, then you know it is that include that is giving the error because you do have HTML tags before that.- Dave Quote Link to comment https://forums.phpfreaks.com/topic/34730-are-cookies-header-information/#findComment-164256 Share on other sites More sharing options...
PC Nerd Posted January 19, 2007 Author Share Posted January 19, 2007 well as you can probably see by the script, i want to validate the login, then create the cookies if it works..... but there is the error......ccan any one help me, becauase i know that i havent sent any thing outive changed the script:[code]<?phpinclude("inc_files/Database_link.inc");if(empty($_POST['User_Name']) || empty($_POST['Password']) || empty($_POST['Valid'])) { $Error1 = "True"; $Error = "True";}require("inc_files/Login_Pics.inc");$img_post_valid = $_POST['IMG_Valid'];$Image_Validate = $IMAGES["B_A-Login_$img_post_valid"];if($_POST['IMG_Valid'] != $Image_Validate) { $Error2 = "True"; $Error = "True";}$SQL_Login = "SELECT User_Name, `Password` FROM General_Stats WHERE User_Name = '".$_POST['User_Name']."'";$Login_Query = mysqli_query($DB_Server, $SQL_Login);if(empty($Login_Query)) { $Error3 = "True"; $Error = "True";}$DB_Login = mysqli_fetch_array($Login_Query);if(empty($DB_Login)) { $Error4 = "True"; $Error = "True";}if(empty($Error)) { include("inc_files/B_A-Create_Cookies.inc"); header("B_A-Base.php");}?><html><head><link rel="stylesheet" type="text/css" href="B_A-CSS.css"><title>Battle Ages Login</title></head><body><table><thead> <td class = 'left'> <img src="Graphics\Small_Logo.GIF" alt="Logo" width = '75%' hight = '75%' align = 'left'> </td> <td class = "centre"> </td> <td class = 'right'> <img src="Graphics\Small_Logo.GIF" alt="Logo" width = '75%' hight = '75%' align = 'right'> </td></thead><tbody><tr><td class = "left"><?php include("inc_files/B_A-Ext_Side_Links.inc"); ?></td><td class = 'centre'><?php#echo "<form name = 'Login_Relocation' action = 'B_A-Base.php' method = 'POST'>\n";#echo "<input type = 'button' name = 'relocation' value = 'Play Battle-Ages'>\n";#echo "</form>";echo "<a href = 'B_A-Base.php' alt = 'Base'>Player Battle-Ages</a>\n";if($Error1 = "True") { die("ERROR 1 You have not filled in the log in fields correctly. Click <a href = 'B_A-Home.php' alt = 'Home'>here</a> to return to the Home Page.");}if($Error2 = "True") { die("ERROR 2 You did not type in the correct validation image. Click <a href = 'B_A-Home.php' alt = 'Home'>here</a> to return to the Home Page.");}if($Error3 = "True") { die("ERROR 3 There was an error in the Database. You have not been logged in. Click <a href = 'B_A-Home.php' alt = 'Home'>here</a> to return to the Home Page.");#.mysqli_error($Login_Query));}if($Error4 = "True") { die("ERROR 4 There was an error in the Database. You have not been logged in. Click <a href = 'B_A-Home.php' alt = 'Home'>here</a> to return to the Home Page.");#.mysqli_error($DB_Login));}?></td><td class = 'right'></td></tr></tbody></table></body></html>[/code]i still get an error about the header to B_A-Base.php, but the cookie create inc file if still the same Quote Link to comment https://forums.phpfreaks.com/topic/34730-are-cookies-header-information/#findComment-164275 Share on other sites More sharing options...
Crimpage Posted January 19, 2007 Share Posted January 19, 2007 I think you want that header to look like:header("Location: B_A-Base.php"); Quote Link to comment https://forums.phpfreaks.com/topic/34730-are-cookies-header-information/#findComment-164278 Share on other sites More sharing options...
PC Nerd Posted January 19, 2007 Author Share Posted January 19, 2007 ok, ive cganged that, BUT im still getting exactly the same errors, AND the css isnt working, but i think thats irrelevant to the phpjust to let you know........ ERROR 1 is being triggered Quote Link to comment https://forums.phpfreaks.com/topic/34730-are-cookies-header-information/#findComment-164282 Share on other sites More sharing options...
PC Nerd Posted January 19, 2007 Author Share Posted January 19, 2007 does anyone else have any ideas to why this is happening Quote Link to comment https://forums.phpfreaks.com/topic/34730-are-cookies-header-information/#findComment-164321 Share on other sites More sharing options...
trq Posted January 19, 2007 Share Posted January 19, 2007 Have you read [url=http://www.phpfreaks.com/forums/index.php/topic,37442.0.html]this[/url] thread? Quote Link to comment https://forums.phpfreaks.com/topic/34730-are-cookies-header-information/#findComment-164327 Share on other sites More sharing options...
Nameless12 Posted January 19, 2007 Share Posted January 19, 2007 PC Nerd Having plain text cookies is insecure. Quote Link to comment https://forums.phpfreaks.com/topic/34730-are-cookies-header-information/#findComment-164330 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.