Jump to content

Cookie problem and yes i don't have any tags before the setcookie


trasseli

Recommended Posts

For some odd reason it doesn't make cookie. I checked it on easyphp 2.0b1 and it worked but not http://www.blackapplehost.com/ that i'm using.

Here's the code:

 

 

<?php

$user=$_POST["user"];

$salasana=$_POST["salasana"];

 

setcookie("user", "$user",time()+3600);

setcookie("salasana", "$salasana",time()+3600);

$url = "editori.php";

Echo" <html>

<body> ";

?>

 

  <?php

echo '<meta http-equiv="refresh" content="5;URL=' . $url .'">';

echo"Tallentta tietoja 5s päästä valmis ja palaa editoriin. ";

 

echo" </body>

</html>";

?>

Try this.

<?php
setcookie('user', $user,time()+3600);
setcookie('salasana', $salasana,time()+3600);
?>

Didn't help i changed my old setcookie to those above and it still wont make cookie for me.

it doesn't even give me anykind of script error neither.

If the cookie is not being set in the browser (you don't indicate how you know it is not being set), you probably do have a header problem due to the BOM characters in a files saved using UTF-8 encoding. Add the following two lines immediately after your <?php tag -

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

Use the domain parameter and see if that helps.

You mean like that?

didn't help.

 

<?php

$user=$_POST["user"];

$salasana=$_POST["salasana"];

$servu=$_SERVER['HTTP_HOST'];

setcookie ("user", $user, time() + 3600, "/", $servu);

setcookie ("salasana", $salasana, time() + 3600, "/", $servu);

$url = "editori.php";

 

  ini_set ("display_errors", "1");

error_reporting(E_ALL);

 

echo '<meta http-equiv="refresh" content="5;URL=' . $url .'">';

echo"Tallentta tietoja 5s päästä valmis ja palaa editoriin. ";

?>

also here's how i know it doesn't make a cookie

 

 

<?php

$url=$_SERVER['PHP_SELF'] ;

  ini_set ("display_errors", "1");

error_reporting(E_ALL);

if($url=='/examples/kirjautuminen.php') { echo"kirjautuminen"; }  else {

$annettu_salasana=$_COOKIE["user"];

$annettu_kayttaja=$_COOKIE["salasana"];

}

 

?>

and the error report

 

Notice: Undefined index: user in /www/blackapplehost.com/t/r/a/trasseli/htdocs/examples/Tunnus.php on line 12

 

Notice: Undefined index: salasana in /www/blackapplehost.com/t/r/a/trasseli/htdocs/examples/Tunnus.php on line 13

 

these are the lines that it's referring to

$annettu_salasana=$_COOKIE["user"];

$annettu_kayttaja=$_COOKIE["salasana"];

It could be another part of your code at fault. i.e. you are setting the cookie value from the $_POST array. This may be empty without you realising it.

 

To test cookies create a test file i.e. test.php

Put the following code in the file and upload it to your webserver

 

setcookie("user", "joe bloggs", time()+3600);
print $_COOKIE['user'];

 

Open the page in the browser and refresh it. What do you see?

Add the following two lines immediately after your <?php tag
If you are not putting the two lines I posted where you were told, you are not going to see any errors that the setcookie() statements might be producing. Putting the two lines after the setcookie() statements is pointless.

Add the following two lines immediately after your <?php tag
If you are not putting the two lines I posted where you were told, you are not going to see any errors that the setcookie() statements might be producing. Putting the two lines after the setcookie() statements is pointless.

 

arning: Cannot modify header information - headers already sent by (output started at /www/blackapplehost.com/t/r/a/trasseli/htdocs/examples/keksi.php:1) in /www/blackapplehost.com/t/r/a/trasseli/htdocs/examples/keksi.php on line 7

 

Warning: Cannot modify header information - headers already sent by (output started at /www/blackapplehost.com/t/r/a/trasseli/htdocs/examples/keksi.php:1) in /www/blackapplehost.com/t/r/a/trasseli/htdocs/examples/keksi.php on line 8

 

ups did read that carefully sorry about that your text here's the error message.

Now how do i fix it? save the file on different program?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.