Session_Start issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gazzieh
Forum Commoner
Posts: 40
Joined: Wed May 19, 2010 7:46 am

Session_Start issue

Post 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?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Session_Start issue

Post 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?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Session_Start issue

Post 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>
katierosy
Forum Commoner
Posts: 27
Joined: Wed Apr 07, 2010 8:39 am

Re: Session_Start issue

Post 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.
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Session_Start issue

Post 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">
 
Post Reply