setcookie returns false

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
asmviper
Forum Newbie
Posts: 1
Joined: Sun Nov 30, 2003 2:51 am

setcookie returns false

Post by asmviper »

I cannot figure out why I can't set a cookie here. I don't think it's a problem with the server because usually I CAN set cookies when I copy paste other people's code, but when I change it to mine it simply does not work. Thanks in advance!

here is the html for a page called checkclass.html:

<html>
<body>

<form action="checkclass.php" method="POST">
Enter the SLN: <input type="text" name="sln" /><BR>
Enter the year: <input type="text" name="year" /><BR>
Enter the quarter: <input type="text" name="quarter" /><BR><BR>
<input type="submit" /><BR><BR>
</form>
</body>
</html>

and the relevant code from checkclass.php

Code: Select all

<?php
	$theray = array($_POST["quarter"],  $_POST["sln"], $_POST["year"]);
	if (!setcookie("cooky", $theray)) /*, time()+36000))*/
		echo "failed to set cookie";

?>
Every single time setcookie returns false. Am I not allowed to use arrays in cookies? I have reason to believe that is not the problem, though I may be wrong. Thanks.
ghost007
Forum Commoner
Posts: 49
Joined: Sat Nov 22, 2003 10:10 am

Post by ghost007 »

try this:

Code: Select all

<?php
if (!setcookie("cooky", implode(",",$theray)))

?>
cheers it's only for fun 8O

siech
Post Reply