php - codeigniter (CI) 的 session 问题

标签 php mysql codeigniter

我在使用 codeigniter 开发的 live 上遇到 php session 错误

A PHP Error was encountered

Severity: Warning

Message: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/userts4m/public_html/development/relatioweb/admin/index.php:1)

Filename: Session/Session.php

Line Number: 140

Backtrace:

File: /home/userts4m/public_html/development/relatioweb/application/admin/controllers/User.php
Line: 9
Function: __construct

File: /home/userts4m/public_html/development/relatioweb/admin/index.php
Line: 293
Function: require_once

在 localhost 工作很好。但是当我在服务器上上传时,我们面临着这个问题。

我该怎么办...

最佳答案

有两种解决方案可以解决此问题。

有时这个错误是由于框架配置错误导致的, 转到文件夹 applications/config 并打开 config.php 像这样在文件的开头写这个

<?php

  if (!defined('BASEPATH')) exit('No direct script access allowed');
    ob_start();
    /* Remaining Part Of your file
     .........................................
   */

另一种解决方法是在类的构造函数中写ob_start() 像这样:

<?php

 if (!defined('BASEPATH')) exit('No direct script access allowed');
   class Your_Controller extends CI_Controller {
     public function __construct() {
       parent::__construct();
       ob_start();
     }
   }

关于php - codeigniter (CI) 的 session 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37052840/

相关文章:

php - 从 SQL 数据库获取最后一篇文章

mysql - mysql 尝试从某些 CHAR_LENGTH 的值中进行选择并按 DESC 排序时出现问题

javascript - 提前从 jquery 类型中获取值

php - 在线 C 编译器

php - 如何找出是否在嵌套数组中

php - 获取一张表的所有数据,而另一张表为空且也应用where子句

php - 使用 www 强制使用 HTTPS 并在 CodeIgniter 中删除 index.php .htaccess

php - 从 mysql php 制作多级数组

MySQL JOIN、WHERE 和 IF 问题

Codeigniter - 调用未定义的函数 set_value()