Page 1 of 1

Session_Start issue

Posted: Wed May 19, 2010 7:59 am
by gazzieh
I have three pages:

index.php is obviously my primary page, which uses an INCLUDE to call the next page.

login.php is called via an INCLUDE from index.php and it's function is to display the login boxes for the users and check the vaildity of the login against the database of users.

Sentry.php does the actual data checking and validation and is called within login.php using a REQUIRED_ONCE command.

If I run login.php everything is fine.

If I run index.php I get the following:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\Program Files\xampp\htdocs\site1\index.php:11) in C:\Program Files\xampp\htdocs\site1\includes\Sentry.php on line 14

The index.php file reads:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Revision Rocks Online</title> 
		<link href="rro.css" rel="stylesheet" type="text/css" />
	</head>
	<body>
		<div id="container">
        	<div id="content_top"></div>
            <div id="content_main">
            	<?php include("controls/login.php") ?>;
            	<a href="page2.php" target="_blank">
                	<div id="anchor1"></div>
                </a>
            </div>
            <div id="content_bottom"></div>
        </div>
	</body>
</html>
If I move the INCLUDE to the very top of the index.php then the login works but I now get the login box outside of my index container div. How can I use the login box where I want to and yet still maintain the functionality of the login system?

Re: Session_Start issue

Posted: Wed May 19, 2010 9:20 am
by social_experiment
gazzieh wrote:login.php is called via an INCLUDE from index.php and it's function is to display the login boxes for the users and check the vaildity of the login against the database of users.
If it is only used to display login boxes (text boxes and then a submit button) why dont you just code it in, instead of using an external file?

Re: Session_Start issue

Posted: Wed May 19, 2010 11:32 am
by flying_circus

Code: Select all

<?php
  /* Anything that sends headers MUST be placed up here, BEFORE any output is sent to the browser!!!
   * Starting a session generally involves sending cookie headers to the client.
   * This MUST be done before you output anything, such as <html> or <head> or <body>
   */
  # Start Session
    session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <title>Revision Rocks Online</title> 
      <link href="rro.css" rel="stylesheet" type="text/css" />
   </head>
   <body>
      <div id="container">
           <div id="content_top"></div>
            <div id="content_main">
               <?php include("controls/login.php") ?>;
               <a href="page2.php" target="_blank">
                   <div id="anchor1"></div>
                </a>
            </div>
            <div id="content_bottom"></div>
        </div>
   </body>
</html>

Re: Session_Start issue

Posted: Thu May 20, 2010 9:23 am
by katierosy
Please see
1. No print before the session_start() call.
2. There is no space char/empty line without any contents in the php page, just focus on the line numbers on your editor, you will be able to notice it.

Re: Session_Start issue

Posted: Thu May 20, 2010 10:50 am
by flying_circus
katierosy wrote:Please see
1. No print before the session_start() call.
2. There is no space char/empty line without any contents in the php page, just focus on the line numbers on your editor, you will be able to notice it.
Is this in response to my reply?

If it is, the following is considered "output" before the session_start() call in the included login.php

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
   <head>
      <title>Revision Rocks Online</title> 
      <link href="rro.css" rel="stylesheet" type="text/css" />
   </head>
   <body>
      <div id="container">
           <div id="content_top"></div>
            <div id="content_main">