Thursday, 15 August 2013

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



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

this question has reply here:

“warning: cannot modify header info - headers sent by” error [duplicate] 6 answers how prepare “headers sent” error in php 11 answers

i understand said error means sending it's output on http protocol (if understood correctly). lines gives me errors setcookie 1 , header 1 (last one). can help me out please? give thanks 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");

?>

setting cookie requires sending info browser. 1 time can't redirect using php or else you'll error you're seeing. seek using session instead.

php cookies header

No comments:

Post a Comment