Jump to content

Cannot modify header


robert_gsfame

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/181380-cannot-modify-header/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/181380-cannot-modify-header/#findComment-956834
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/181380-cannot-modify-header/#findComment-956909
Share on other sites

Archived

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

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