Jump to content

Are cookies header information


PC Nerd

Recommended Posts

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 strange

im just wondering is cookies are actually header information, or if this is a strang error
Link to comment
Share on other sites

technically... no
however...

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 :-)
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

<?php

include("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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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


Link to comment
Share on other sites

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 out


ive changed the script:


[code]<?php

include("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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.