Jump to content

Recommended Posts

I am moving to a different hosting site that is using php 5.2 from one that has 5.3. I am running into an error with my session_start() that worked just fine before. Was wondering if I could get some pointers.

 

These are the errors that I get

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started atindex.php:10) in header.php on line 5

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at index.php:10) in header.php on line 5

 

Notice: Undefined index: login in header.php on line 6

 

Notice: Undefined index: rank in header.php on line 7

 

Notice: Undefined variable: loggedinusername in header.php on line 8

 

Notice: Undefined variable: loggedinuseremail in header.php on line 9

 

Warning: Cannot modify header information - headers already sent by (output started at index.php:10) in header.php on line 10

 

Notice: Undefined index: rank in header.php on line 15

 

 

This is what I have in my header that is included in every page.

4   <?
5   session_start();
6   if(!$_SESSION['login']){
7   $_SESSION['rank'];
8   $_SESSION['loggedinusername'] = $loggedinusername;
9   $_SESSION['loggedinuseremail'] = $loggedinuseremail;
10  header("location:login.php");
11  }
12  ?>
13
14  <?php
15  $rank=$_SESSION['rank'];
16  $loggedinusername=$_SESSION['loggedinusername'];
17  $loggedinuseremail=$_SESSION['loggedinuseremail'];
18  ?>

Link to comment
https://forums.phpfreaks.com/topic/255693-moving-from-php-53-to-52/
Share on other sites

Lines 1-3 are as follows

 

1   <?php ini_set ("display_errors", "1");
2   error_reporting(E_ALL);
3   ?>

 

removed line 13 so it is now as follows

 

10  header("location:login.php");
11  }
13  ?>
14  <?php
15  $rank=$_SESSION['rank'];

 

The errors are the same the last one being at line 14 now

 

Thank you

The error message tells you where the output started:

(output started atindex.php:10)

 

Have a look at index.php, somewhere around line 10. Some kind of output was sent to the browser there. You cannot have any output to the browser before a session start (which has to send headers). Anything in your code that is not between php open and close tags is sent to the browser.

 

Also, you should avoid using the short tags ("<?"), instead, use the full tags ("<?php").

Also, there is no real reason to jump in and out of PHP like that:

 

<?php
// Some PHP code here
?>

<?php
// more PHP code here 
// ... and nothing between the close and open tags above
?>

 

You should just stay in PHP. Otherwise, that blank line between the close tag and the open tag will be sent to the browser

 

<?php
// Some PHP code here

// more PHP code here 
?>

 

Line 10 in index.php is the include for the header

 

<div id="header"> <?php include_once"header.php" ?></div>

 

lines 1-9 are where I have the title, css and what not everything above there is HTML

 

The way it was set up on my old site was that if you were not logged in it would send you right to the log in page right now it pulls up the index page with the errors. 

 

Thanks again

 

The jumping in and out of php and using the short tags are bad habits that I have picked up from teaching myself php and am working on fixing.

When I moved from hosting the site myself there were not errors and everything worked just fine. When I went to the site and wasn't logged it I would be redirected to the log in page. From there I could log in and move around the site with no problem. When I moved to a hosting site yesterday is when the problems came up. The only 2 things that have changed was going from php 5.3 to 5.2 and who I'm hosting it with. I had it configured to report the errors seance I put the page together because its a work in progress.

Line 10 in index.php is the include for the header

 

<div id="header"> <?php include_once"header.php" ?></div>

 

lines 1-9 are where I have the title, css and what not everything above there is HTML

 

HTML is, by definition, output sent to the browser. That <DIV> tag just before your include, is being sent to the browser, as is the "title, css and what not ..." before it.

 

The way it was set up on my old site was that if you were not logged in it would send you right to the log in page right now it pulls up the index page with the errors. 

 

IF this was working on another site, it may have had output buffering on, which would capture the output (and buffer it) until the page was done. I don't consider that to be a solution, but it might be an explanation.

Thanks for all the help so far. I have moved the header include to line 1 and still get the error the only difference is the line number

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at index.php:1) in header.php on line 5

 

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at index.php:1) in header.php on line 5

 

I then created a test page with just the header include and get the same errors.

If you browse directly to header.php, do you still get an error? If so, it's probably a byte order mark (BOM). Open the file in your editor, and drawbridge it as UTF-8 without BOM. There should be a config setting for whether to include a BOM or not.

I did not get the problem if I went right to the header. I had it in the header so I would flow easily through the whole site. I took the header and made it the index.php and renamed the old index to something else and made an include on the new index for the main page. This allows the log in for the main page now I have the problem of the header and session not flowing through the whole site.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.