Jump to content

Archived

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

drdysdy

Problem setting cookies

Recommended Posts

Ok, I've been trying for the last 12 hours to get this damn script to set one damned cookie! LOL. But I can't figure it out so I'm asking you people for help!

[code]<html>
<title>Set ship cookie</title>
<body>
<?php
include "dbinfo.inc.php";

if (isset($_POST['submit'])){
$objid = $_POST['objid'];
setcookie( 'objid', $objid, time()+60*60*24*30, '/', '*edited*');
echo "<br>$objid";
}else{
echo "The post didn't come through";
}


?>
</body>

</html>[/code]

Ok, and before you ask dbinfo does not output anything.

Help would be appreciated

Also

[code]<?php
include "dbinfo.inc.php";

if (isset($_POST['submit'])){
$objid = $_POST['objid'];


$success = setcookie( 'objid', $objid);
if($success){
echo "succeeded";
}elseif(!$success){
echo "failed";
}else{
echo"hmm";
}
setcookie( 'objid', $objid, time()+60*60*24*30, '/', '*edited*');
echo "$objid";
}else{
echo "The post didn't come through";
}


?>[/code]

This doesn't work either (Forgot not to output anything to the browser before setting the cookie)

Share this post


Link to post
Share on other sites
the second bit of code should be telling you success or failure -- do you get any output at all?

Also, you're checking for $_POST['submit'] but you're assigning $_POST['objid'] without testing for it. You might want to include a print_r($_POST); to make sure all of your expected variables actually exist.

Share this post


Link to post
Share on other sites
In the following code your cookie wont be set as your are outputting html to the browser and so PHP cannot set the cookie. You cannot sent anytrhing to the browser before the use of setcookie.[code]<html>
<title>Set ship cookie</title>
<body>
<?php
include "dbinfo.inc.php";

if (isset($_POST['submit'])){
$objid = $_POST['objid'];
setcookie( 'objid', $objid, time()+60*60*24*30, '/', '*edited*');
echo "<br>$objid";
}else{
echo "The post didn't come through";
}


?>
</body>

</html>[/code]

Share this post


Link to post
Share on other sites
[!--quoteo(post=367205:date=Apr 21 2006, 09:55 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 21 2006, 09:55 AM) [snapback]367205[/snapback][/div][div class=\'quotemain\'][!--quotec--]
In the following code your cookie wont be set as your are outputting html to the browser and so PHP cannot set the cookie. You cannot sent anytrhing to the browser before the use of setcookie.[code]<html>
<title>Set ship cookie</title>
<body>
<?php
include "dbinfo.inc.php";

if (isset($_POST['submit'])){
$objid = $_POST['objid'];
setcookie( 'objid', $objid, time()+60*60*24*30, '/', '*edited*');
echo "<br>$objid";
}else{
echo "The post didn't come through";
}
?>
</body>

</html>[/code]
[/quote]

Yea i cought that, but still it doesn't work.
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
the second bit of code should be telling you success or failure -- do you get any output at all?
[/quote]
its outputting 'failure'
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
Also, you're checking for $_POST['submit'] but you're assigning $_POST['objid'] without testing for it. You might want to include a print_r($_POST); to make sure all of your expected variables actually exist.
[/quote]

Thats what the echo "<br>$objid"; is for =P

Share this post


Link to post
Share on other sites

×

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.