Jump to content

Problem setting cookies


drdysdy

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)
Link to comment
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.
Link to comment
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]
Link to comment
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
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.