drdysdy Posted April 20, 2006 Share Posted April 20, 2006 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><?phpinclude "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 appreciatedAlso [code]<?phpinclude "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) Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted April 20, 2006 Share Posted April 20, 2006 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. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted April 21, 2006 Share Posted April 21, 2006 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><?phpinclude "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 Link to comment Share on other sites More sharing options...
drdysdy Posted April 21, 2006 Author Share Posted April 21, 2006 [!--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><?phpinclude "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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.