简体   繁体   中英

Cannot modify header information - headers already sent by (i am using cookie in my set i want to reset the cookie)

//Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/students/public_html/beta/inner/logout.php:1) in /home/students/public_html/beta/inner/logout.php on line 4

//Array ( [cookie_name] => gausulpersonalive@gmail.com [cookie_id] => 1 [PHPSESSID] => c0abab10adf83838ee357bc6dbdf7cfd )

//Warning: Cannot modify header information - headers already sent by (output started at /home/students/public_html/beta/inner/logout.php:1) in /home/students/public_html/beta/inner/logout.php on line 15

//Warning: Cannot modify header information - headers already sent by (output started at /home/students/public_html/beta/inner/logout.php:1) in /home/students/public_html/beta/inner/logout.php on line 16

//Notice: Undefined variable: _COOKIE in /home/students/public_html/beta/inner/logout.php on line 18

//LOGOUT PAGe CODE

<?php 
ob_start();
//error_reporting(0);
session_start();
session_cache_limiter('none');
ini_set(‘display_errors’, true); 
ini_set(‘display_startup_errors’, true);
 error_reporting (E_ALL);
print_r ($_COOKIE);
     unset($_SESSION['useremail']);
     unset($_SESSION['userid']);
     unset($_SESSION['user_form_data']);
     unset($_SESSION['url']);
if(isset($_COOKIE)){
setcookie("cookie_name",null,time()-60*60*24*100,'/');
setcookie("cookie_id",null,time()-60*60*24*100,'/');
unset($_COOKIE);
print_r ($_COOKIE);
}
session_destroy();
ob_end_flush();
?>

//cookie set page

if($cookie=='on')
    {
        setcookie("cookie_name",$users['email'],time()+60*60*24*100);


        setcookie("cookie_id",$users['id'],time()+60*60*24*100);


    }       

but cookie is not unset!!!!!

1 - Try to find white spaces before

2 - Try to find white spaces after ?>, delete them.

3 - Delete any echo that you can be doing before the code that modify the headers.

4 - [THIS ONE SAVED MY LIFE] try to change the file encoding of your php file to "ANSI".

good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM