Php not setting cookie


Php not setting cookie

?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class Login extends Controller
{
function index()
{
    $data['main'] ='';
    $data['error'] = '';
    if($this->input->post('username'))
    {
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        $config = $this->maincore->get_config();
        if($username == $config['admin_username'] && md5($password) == $config['admin_password']){
        $value = $username.".".md5($password);

        $time = 9000;
        if($this->input->post('remember')) { 
        $time =  time()+3600*24*5;  
        }
    setcookie("feeder_login", $value, $time, '/');
    echo '<meta http-equiv="refresh" content="0;url='.$this->config->site_url().'">';
    exit;

我在chrome和Firefox中清除了我的cookie。在我的脚本运行后。根本没有新的饼干。

我知道脚本正在工作,因为它在运行后将我重定向到主页。

设置 cookie 时,您不能在此之前输出任何内容。我很确定你在setcookie()之前已经用"echo()"输出了一些东西.如果你前面有一个空字符

<?php
setcookie("test", "this is a cookie");
?>

它应该真的有效。