Saturday 11 November 2017

cookies - Warning: Cannot modify header information - headers already sent by... PHP

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.



$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");


?>

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...