trasseli Posted March 11, 2009 Share Posted March 11, 2009 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>"; ?> Link to comment https://forums.phpfreaks.com/topic/148922-cookie-problem-and-yes-i-dont-have-any-tags-before-the-setcookie/ Share on other sites More sharing options...
WolfRage Posted March 11, 2009 Share Posted March 11, 2009 Try this. <?php setcookie('user', $user,time()+3600); setcookie('salasana', $salasana,time()+3600); ?> Link to comment https://forums.phpfreaks.com/topic/148922-cookie-problem-and-yes-i-dont-have-any-tags-before-the-setcookie/#findComment-781953 Share on other sites More sharing options...
trasseli Posted March 11, 2009 Author Share Posted March 11, 2009 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. Link to comment https://forums.phpfreaks.com/topic/148922-cookie-problem-and-yes-i-dont-have-any-tags-before-the-setcookie/#findComment-781968 Share on other sites More sharing options...
WolfRage Posted March 11, 2009 Share Posted March 11, 2009 Should work, guess you will have to check your configuration settings???? Link to comment https://forums.phpfreaks.com/topic/148922-cookie-problem-and-yes-i-dont-have-any-tags-before-the-setcookie/#findComment-781972 Share on other sites More sharing options...
JonnoTheDev Posted March 11, 2009 Share Posted March 11, 2009 how do you know there is no cookie set. have you tried to print the value setcookie("user", "joe bloggs", time()+3600); print $_COOKIE['user']; Link to comment https://forums.phpfreaks.com/topic/148922-cookie-problem-and-yes-i-dont-have-any-tags-before-the-setcookie/#findComment-781981 Share on other sites More sharing options...
revraz Posted March 11, 2009 Share Posted March 11, 2009 Use the domain parameter and see if that helps. Link to comment https://forums.phpfreaks.com/topic/148922-cookie-problem-and-yes-i-dont-have-any-tags-before-the-setcookie/#findComment-781988 Share on other sites More sharing options...
PFMaBiSmAd Posted March 11, 2009 Share Posted March 11, 2009 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); Link to comment https://forums.phpfreaks.com/topic/148922-cookie-problem-and-yes-i-dont-have-any-tags-before-the-setcookie/#findComment-782003 Share on other sites More sharing options...
trasseli Posted March 11, 2009 Author Share Posted March 11, 2009 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"]; Link to comment https://forums.phpfreaks.com/topic/148922-cookie-problem-and-yes-i-dont-have-any-tags-before-the-setcookie/#findComment-782190 Share on other sites More sharing options...
JonnoTheDev Posted March 11, 2009 Share Posted March 11, 2009 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? Link to comment https://forums.phpfreaks.com/topic/148922-cookie-problem-and-yes-i-dont-have-any-tags-before-the-setcookie/#findComment-782201 Share on other sites More sharing options...
PFMaBiSmAd Posted March 11, 2009 Share Posted March 11, 2009 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. Link to comment https://forums.phpfreaks.com/topic/148922-cookie-problem-and-yes-i-dont-have-any-tags-before-the-setcookie/#findComment-782209 Share on other sites More sharing options...
trasseli Posted March 11, 2009 Author Share Posted March 11, 2009 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? Link to comment https://forums.phpfreaks.com/topic/148922-cookie-problem-and-yes-i-dont-have-any-tags-before-the-setcookie/#findComment-782225 Share on other sites More sharing options...
premiso Posted March 11, 2009 Share Posted March 11, 2009 Make sure there are no whitespaces before the <?php If there are none, then yes. Try saving it using Notepad and see what happens. Bad: <?php Good: <?php Link to comment https://forums.phpfreaks.com/topic/148922-cookie-problem-and-yes-i-dont-have-any-tags-before-the-setcookie/#findComment-782227 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.