Session issue with codeigniter (CI)

Multi tool use
Multi tool use


Session issue with codeigniter (CI)



I am getting php session error on my live developed using codeigniter


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



Working at localhost fine. But when i uploded at server we are facing this issue.



What should i do ...





i think somewhere you forgot to remove print_r();die; or echo statement
– Kunal
May 5 '16 at 14:12





what's on line 1 of this file? /home/userts4m/public_html/development/relatioweb/admin/index.php
– Dale
May 5 '16 at 14:13


/home/userts4m/public_html/development/relatioweb/admin/index.php





Change something in constructor of User.php admin controller.
– Tpojka
May 5 '16 at 14:43


User.php




7 Answers
7



These both solutions work for me try it. May be it 'll work for you.



Some times this error occurred due to the wrong configuration Of framework,
go to the folder applications/config and open up the config.php write this in the starting of file like this


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



Another solution is to write ob_start() in the constructor of the class
like this:


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



This usually means that somewhere you've already got a session_start() and a second one will throw this error. Remove the redundant one.


session_start()



the problem is well explained here How to fix "Headers already sent" error in PHP



In order to solve this I needed to implement
the concept of output-buffering (Output buffering is a mechanism in which instead of sending a response immediately to browser we buffer it somewhere so that we can send it at once when whole content is ready ).
So as the error indicate the problem occurs in index.php
what I did I inserted


ob_start();



at the beginning of index.php



Try using @session_start(); It will bypass the error and session will be start.
Please note @session_start() is your first line of the code. Do not execute or echo anything before it.



As per @kunal and @dale suggestion there was a space in /home/userts4m/public_html/development/relatioweb/admin/index.php


@kunal


@dale


/home/userts4m/public_html/development/relatioweb/admin/index.php



In this file may have blank space before start PHP tag.



Check the controller file, if there are spaces before the php tag remove it.





This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
– Sinto
Jul 3 at 5:35






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

KvwwJak,8SxBz10x 6sQGqp83kCVvncOv6BQfKLIXo4K,n8,A94otXfA 1SCIEwQV
Pz2AS8Yj8z,HrutoxR9X22PXlobzdJ7wawzG7pVHsBqF,9ROKtclW1I

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications