# Sessions - stopped working

**URL:** <https://www.phphelp.com/t/sessions-stopped-working/21342>\
**Category:** Security and PHP\
**Created:** [October 20, 2013, 9:14am UTC](https://www.phphelp.com/t/sessions-stopped-working/21342 "2013-10-20T09:14:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandrad23](https://www.phphelp.com/letter_avatar_proxy/v4/letter/s/f1d935/32.png) [@sandrad23](https://www.phphelp.com/u/sandrad23)\
**Post date:** [October 20, 2013, 9:14am UTC](https://www.phphelp.com/t/sessions-stopped-working/21342/1 "2013-10-20T09:14:53Z")

</div>

Hi

I am new to php and have been working on setting up a website with certain pages password protected. I have a user registration form saving the information on mysql which seems to work fine and when I launched the login/registration part of my website it seemed to work fine for the first 24 hours (with over 100 users registering).

After this initial period it just stopped working - the registration is still working and new users can been added but the first of the password protected pages won’t load.

This is the php script that I have to check for the session variable being set before loading the page or redirecting to the page called assess.php where the user is asked to login or register

\<?php session\_start(); // Start the session. if (!isset($\_SESSION['username'])) { (header("Location: assess.php")); exit(); // Quit the script. } ?\>

Nothing seems to happen - it just shows a blank page where as initially it all worked fine.  
Any suggestions - what am I missing?  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![Topcoder](https://www.phphelp.com/user_avatar/www.phphelp.com/topcoder/32/4356_2.png) [@Topcoder](https://www.phphelp.com/u/Topcoder)\
**Post date:** [October 20, 2013, 1:28pm UTC](https://www.phphelp.com/t/sessions-stopped-working/21342/2 "2013-10-20T13:28:27Z")

</div>

Do you have errors reporting turned in?

If not you can add these statements just after the \<?php

[php]ini\_set(‘display\_errors’,1);  
ini\_set(‘display\_startup\_errors’,1);  
error\_reporting(-1);[/php]

It might give you some clues as to what can be happening.

---

<div class="post-metadata">

**Author:** ![sandrad23](https://www.phphelp.com/letter_avatar_proxy/v4/letter/s/f1d935/32.png) [@sandrad23](https://www.phphelp.com/u/sandrad23)\
**Post date:** [October 20, 2013, 2:35pm UTC](https://www.phphelp.com/t/sessions-stopped-working/21342/3 "2013-10-20T14:35:04Z")

</div>

Hi

Thanks for the quick reply - I added the code and got  
Cannot modify header information - headers already sent by (output started at /www/sites/f91/56…

referring to the line I used to redirect to the login page using header(‘Location’:assess.php)

As I said initially it all worked fine for about 24 hours and then suddenly stopped?  
Any help much appreciated.

---

<div class="post-metadata">

**Author:** ![Topcoder](https://www.phphelp.com/user_avatar/www.phphelp.com/topcoder/32/4356_2.png) [@Topcoder](https://www.phphelp.com/u/Topcoder)\
**Post date:** [October 20, 2013, 2:48pm UTC](https://www.phphelp.com/t/sessions-stopped-working/21342/4 "2013-10-20T14:48:48Z")

</div>

> As I said initially it all worked fine for about 24 hours and then suddenly stopped?

 - Stop thinking that way, something got changed. 

I have a feeling you’re not sharing all the code…

That error means that you most likely started to output HTML code and then you are redirecting it to a new page which is not allowed.

Hence,

output started at /www/sites/f91/56…

You’re outputting something there, then doing a re-direct is that mini snippet you posted.

---

<div class="post-metadata">

**Author:** ![sandrad23](https://www.phphelp.com/letter_avatar_proxy/v4/letter/s/f1d935/32.png) [@sandrad23](https://www.phphelp.com/u/sandrad23)\
**Post date:** [October 20, 2013, 3:38pm UTC](https://www.phphelp.com/t/sessions-stopped-working/21342/5 "2013-10-20T15:38:09Z")

</div>

The following code is at the top of the password protected page…before the html  
[php]\<?php  
ini\_set(‘display\_errors’,1);  
ini\_set(‘display\_startup\_errors’,1);  
error\_reporting(-1);  
session\_start();  
if (!isset($\_SESSION[‘username’])) {  
(header(“Location: assess.php”));  
exit(); // Quit the script.  
}  
?\>

 SASSMAIN [/php]

Plus just realised that I had put your suggested reporting code after the session start…the error messages now look like this

[php]Warning: session\_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /www/sites/f91/56e/test.mathsbox.org.uk/web/sass.php:1) in /www/sites/f91/56e/test.mathsbox.org.uk/web/sass.php on line 5

Warning: session\_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /www/sites/f91/56e/test.mathsbox.org.uk/web/sass.php:1) in /www/sites/f91/56e/test.mathsbox.org.uk/web/sass.php on line 5

Warning: Cannot modify header information - headers already sent by (output started at /www/sites/f91/56e/test.mathsbox.org.uk/web/sass.php:1) in /www/sites/f91/56e/test.mathsbox.org.uk/web/sass.php on line 7[/php]

Any suggestions/help greatly appreciated

---

<div class="post-metadata">

**Author:** ![JimL](https://www.phphelp.com/user_avatar/www.phphelp.com/jiml/32/1842_2.png) [@JimL](https://www.phphelp.com/u/JimL)\
**Post date:** [October 20, 2013, 3:52pm UTC](https://www.phphelp.com/t/sessions-stopped-working/21342/6 "2013-10-20T15:52:20Z")

</div>

You have some html output somewhere before that session\_start runs

---

<div class="post-metadata">

**Author:** ![HackTactics](https://www.phphelp.com/user_avatar/www.phphelp.com/hacktactics/32/973_2.png) [@HackTactics](https://www.phphelp.com/u/HackTactics)\
**Post date:** [October 26, 2013, 12:26pm UTC](https://www.phphelp.com/t/sessions-stopped-working/21342/7 "2013-10-26T12:26:43Z")

</div>

> [@sandrad23](#):
>
> The following code is at the top of the password protected page…before the html  
> [php]\<?php ini\_set('display\_errors',1); ini\_set('display\_startup\_errors',1); error\_reporting(-1); session\_start(); if (!isset($\_SESSION['username'])) { (header("Location: assess.php")); exit(); // Quit the script. } ?\>
> 
> SASSMAIN [/php]
> 
> Plus just realised that I had put your suggested reporting code after the session start…the error messages now look like this
> 
> [php]Warning: session\_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /www/sites/f91/56e/test.mathsbox.org.uk/web/sass.php:1) in /www/sites/f91/56e/test.mathsbox.org.uk/web/sass.php on line 5
> 
> Warning: session\_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /www/sites/f91/56e/test.mathsbox.org.uk/web/sass.php:1) in /www/sites/f91/56e/test.mathsbox.org.uk/web/sass.php on line 5
> 
> Warning: Cannot modify header information - headers already sent by (output started at /www/sites/f91/56e/test.mathsbox.org.uk/web/sass.php:1) in /www/sites/f91/56e/test.mathsbox.org.uk/web/sass.php on line 7[/php]
> 
> Any suggestions/help greatly appreciated

Is this file included in another by any chance?
