robert_gsfame Posted November 13, 2009 Share Posted November 13, 2009 I really confused why was this happened when i was trying to set cookie Page1.php <?php session_start();?> <?php require_once('configuration.php');?> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx <?php if($_COOKIE["cookies1"]){ $cookies1=$_COOKIE["cookies1"]; $checked1="CHECKED";} ?> <html> <head> <body> <form name="form1" method="post" action="form2.php"> <input type="text" name="text1" value=<?php echo $cookies1> <input type="checkbox" name="cookies" $checked1>cookies <input type="submit"> </form> </body> </head> then in page2.php <?php session_start();?> <?php require_once('configuration.php');?> xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx <?php $cookies1=$_POST['cookies']; if(isset($cookies1)){ setcookie("cookies",$_POST['text']); }?> <html> <head> <body> <form name="form1" method="post" action="form2.php"> <input type="text" name="text1" value=<?php echo $cookies1> <input type="checkbox" name="cookies" $checked1>cookies <input type="submit"> </form> </body> </head> Which part is incorrect as it always give me this result: CANNOT MODIFY HEADER BLABLABLABLABLABLA, and it stated that this part <?php $cookies1=$_POST['cookies']; if(isset($cookies1)){ setcookie("cookies",$_POST['text']); }?> on page2.php seems to be incorrect Quote Link to comment https://forums.phpfreaks.com/topic/181380-cannot-modify-header/ Share on other sites More sharing options...
JonnoTheDev Posted November 13, 2009 Share Posted November 13, 2009 Read the massive sticky thread at the top of this forum http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment https://forums.phpfreaks.com/topic/181380-cannot-modify-header/#findComment-956786 Share on other sites More sharing options...
PFMaBiSmAd Posted November 13, 2009 Share Posted November 13, 2009 And since the error message states where the output is occurring at that is preventing the setcookie/header from working, it would take seeing at least the part of the error message that states where that output was started at (i.e. (output started at ....\page2.php:x) where x is the line number) for any one to be able to specifically help you with the problem in your code. Quote Link to comment https://forums.phpfreaks.com/topic/181380-cannot-modify-header/#findComment-956834 Share on other sites More sharing options...
robert_gsfame Posted November 13, 2009 Author Share Posted November 13, 2009 <?php $cookies1=$_POST['cookies']; if(isset($cookies1)){ setcookie("cookies",$_POST['text']); }?> This line was said to be the error!! Quote Link to comment https://forums.phpfreaks.com/topic/181380-cannot-modify-header/#findComment-956897 Share on other sites More sharing options...
robert_gsfame Posted November 13, 2009 Author Share Posted November 13, 2009 if i use ob_start(), is it solving the problem?? Quote Link to comment https://forums.phpfreaks.com/topic/181380-cannot-modify-header/#findComment-956903 Share on other sites More sharing options...
mrMarcus Posted November 13, 2009 Share Posted November 13, 2009 try eliminating the whitespace at the top of your scripts: <?php session_start(); //on second line with no whitespace before it; require_once('configuration.php'); //there's no reason to keep opening and closing php tags for every line of code you write .. keep it fluid; //continue; ?> Quote Link to comment https://forums.phpfreaks.com/topic/181380-cannot-modify-header/#findComment-956909 Share on other sites More sharing options...
JonnoTheDev Posted November 13, 2009 Share Posted November 13, 2009 if i use ob_start(), is it solving the problem?? That is not a solution. You must have a whitespace character somewhere if you havent output anything to the screen. often found after ?> tags in includes, which are hard to spot. Quote Link to comment https://forums.phpfreaks.com/topic/181380-cannot-modify-header/#findComment-956919 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.