CodeIgniter Forums
500 Internal Server Error because of a line of code in system/core/CodeIgniter.php - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: 500 Internal Server Error because of a line of code in system/core/CodeIgniter.php (/showthread.php?tid=57412)

Pages: 1 2 3


500 Internal Server Error because of a line of code in system/core/CodeIgniter.php - El Forum - 03-13-2013

[eluser]brianbabu[/eluser]
This is the code on viewing the source. I dont think there is anything useful

Code:
We'll take you to the dashboard shortly<div  solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  Cannot modify header information - headers already sent by (output started at D:\PLESKVHOSTS\vhosts\pdocricket.com\httpdocs\TestCMS\application\controllers\admin.php:42)</p>
<p>Filename: libraries/Session.php</p>
<p>Line Number: 675</p>

</div><div  solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  Cannot modify header information - headers already sent by (output started at D:\PLESKVHOSTS\vhosts\pdocricket.com\httpdocs\TestCMS\application\controllers\admin.php:42)</p>
<p>Filename: helpers/url_helper.php</p>
<p>Line Number: 542</p>

</div>

However, commenting out the line did make a change. It doesn't show the error but it reverted back to the admin login screen from the dashboard. I guess the session data isn't getting set.


500 Internal Server Error because of a line of code in system/core/CodeIgniter.php - El Forum - 03-13-2013

[eluser]brianbabu[/eluser]
should i use....
Dariusz Debowczyk's Session Class ???


500 Internal Server Error because of a line of code in system/core/CodeIgniter.php - El Forum - 03-13-2013

[eluser]TheFuzzy0ne[/eluser]
I think that's your answer. The only output is what you've echoed, and the error appears immediately after.

It seems pretty pointless to me echoing a message and redirecting. Redirecting uses headers, so it's important not to output any data before sending the headers, because they can't be set once your output has been sent.

Your code is telling the browser to redirect, so that's what I'd expect to happen. What were you expecting to happen?

If you really want to display a message to the user, it would make more sense doing it by displaying a view, and setting a meta redirect.


500 Internal Server Error because of a line of code in system/core/CodeIgniter.php - El Forum - 03-13-2013

[eluser]brianbabu[/eluser]
well yeah it redirects to the dashboard. my dashboard checks if a session is set or not. If yes, it displays the dashboard or else re-directs back to the login page. As of now, even after logging it redirects back to the login page.


500 Internal Server Error because of a line of code in system/core/CodeIgniter.php - El Forum - 03-13-2013

[eluser]brianbabu[/eluser]
Its not yet resolved, TheFuzzy0ne Sad It doesn't record my session. it just re-directs back to the login screen. Plz Help!!


500 Internal Server Error because of a line of code in system/core/CodeIgniter.php - El Forum - 03-13-2013

[eluser]TheFuzzy0ne[/eluser]
What's your dashboard code?

In your dashboard method, what's the output of the following:

Code:
print_r($this->session->all_userdata());
die();



500 Internal Server Error because of a line of code in system/core/CodeIgniter.php - El Forum - 03-13-2013

[eluser]brianbabu[/eluser]
Fatal error: Call to undefined method CI_Session::all_userdata() in D:\PLESKVHOSTS\vhosts\pdocricket.com\httpdocs\TestCMS\application\controllers\dashboard.php on line 23

This is what my dashboard does:
Code:
function __construct()
{
  parent::__construct();
  $this->is_logged_in();
  $this->load->model('Login_model');
  $this->load->model('Settings_model');
  $this->load->model('Category_model');
  $this->load->model('Page_model');
  $this->load->model('Post_model');

}

function is_logged_in()
{
  if($this->session->userdata('is_logged_in')!=TRUE)
  {
   redirect("admin");
  }
}

public function index()
{
  $users_id=$this->session->userdata('users_id');
  
  $data=array(
   "username"    =>  $this->Login_model->userinfobyid('users_username', $users_id),
   "avatar"    =>  $this->Login_model->userinfobyid('users_avatar', $users_id),
   "name"     =>  $this->Login_model->userinfobyid('users_name', $users_id),
   "pagetitle"   => 'Dashboard',
   "dynamic_loading"  => $this->Settings_model->fetchsetting("site_dynamic_loading"),
   "categories"  => $this->allcategories()
  );
  $data['latestposts']=$this->Post_model->latestpost("",5);
  $data['latestpages']=$this->Page_model->latestpage(5);
  $this->load->view('admin/dashboard', $data);
}



500 Internal Server Error because of a line of code in system/core/CodeIgniter.php - El Forum - 03-13-2013

[eluser]TheFuzzy0ne[/eluser]
I suggest you make your is_logged_in() method protected, or prefix it with an underscore so that it's not accessible from the outside.

Something's not right with your sessions class. $this->session->all_userdata() should definitely be there, unless you've overidden the session library with your own. This could explain why your userdata is not being saved.

Also, you can enable the profiler with:
Code:
$this->output->enable_profiler(TRUE);

That should help you to see what's going on.


500 Internal Server Error because of a line of code in system/core/CodeIgniter.php - El Forum - 03-13-2013

[eluser]brianbabu[/eluser]
Thank for the tip man.

i refreshed the page and check the output for

Code:
$this->session->all_userdata();

There is no output from that line. No sessions are being recorded.


500 Internal Server Error because of a line of code in system/core/CodeIgniter.php - El Forum - 03-13-2013

[eluser]brianbabu[/eluser]
Ok there is a good news!

[code
print_r($this->session->all_userdata());
][/code]

did give me an array. So does that mean the sessions are working?