0

I understand that the said error means that something is sending it's output over the HTTP protocol (if I understood correctly). The lines which it gives me errors are the setcookie one and the header one (last one). Can anyone help me out with this please? Thank you.

<?php
$a = 'thisissomestring=='; 
$b = 'thisissomestring==';
$encryptedData = base64_decode($a);
$iv = base64_decode($b);
$appKey ='thisissomestring';
$td = mcrypt_module_open(MCRYPT_SERPENT, '', MCRYPT_MODE_CBC, '');
$ks = mcrypt_enc_get_key_size($td);
$key = substr($appKey, 0, $ks);
mcrypt_generic_init($td, $key, $iv);
$decrypted = mdecrypt_generic($td, $encryptedData);
$str = $decrypted;
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
$file = file($decrypted);
$output = $file[0];
if( !isset( $_COOKIE['thisismycookie'] ) )
{
    setcookie('thisismycookie', $output, time() + 600, "/", $_SERVER['HTTP_HOST']);
}
else
{
    echo 'Action not allowed [3]';
    die();
}
unset($file[0]);
file_put_contents($str, $file);
header("Location: http://www.mysite.com/something");

?>

John Conde
  • 217,595
  • 99
  • 455
  • 496
Krešimir Čulina
  • 93
  • 1
  • 7
  • 19

1 Answers1

2

Setting a cookie requires sending data to the browser. Once you do that you can't redirect using PHP or else you'll get the error you're seeing. Try using a session instead.

John Conde
  • 217,595
  • 99
  • 455
  • 496