Jump to content


Photo

Problem setting cookies


  • Please log in to reply
3 replies to this topic

#1 drdysdy

drdysdy
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 20 April 2006 - 08:34 PM

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!

<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>

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

Help would be appreciated

Also

<?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";
 }


 ?>

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

#2 michaellunsford

michaellunsford
  • Members
  • PipPipPip
  • Advanced Member
  • 1,023 posts
  • LocationLouisiana, USA

Posted 20 April 2006 - 10:41 PM

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.

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 21 April 2006 - 02:55 PM

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


#4 drdysdy

drdysdy
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 21 April 2006 - 08:01 PM

[!--quoteo(post=367205:date=Apr 21 2006, 09:55 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 21 2006, 09:55 AM) View Post[/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.
<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>
[/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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users