Jump to content


User Registration- Chapter 16

  • Please log in to reply
1 reply to this topic

#1 Ryan R

Ryan R

    Advanced Member

  • Members
  • PipPipPip
  • 63 posts
  • LocationGravenhurst, ON, Canada

Posted 16 June 2011 - 9:23 AM

Hi all,

I coded the web pages according to the book'php6 and mysql5'. It was ok when I put it up on my local computer. However, when I put it up on my server, there's an error occurred. I don't how I can figure it out. Thank you in advance for your help.

The error message I got is this:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/ryandivi/public_html/template-registration/includes/config.inc.php:69) in /home/ryandivi/public_html/template-registration/includes/header.html on line 8

I am posting my header page, config page and index page below..


<header page>

<?php #script 16.1 - header.html
//This page begins the HTML header for the site

//start output buffering

//initialize a session;

//check for a $page_title value;
$page_title='User Registration';


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title><?php echo $page_title ?></title>

<style type="text/css" media="screen">
@import "includes/layout.css";


<div id="header">User Registration</div>
<div id="Content">
<!-- end of header -->

<config page>

<?php #script 16.3 -config.inc.php
/*This script:
* - define constants and settings
* - dictates how errors are handled
* - defines useful functions

//Document who created this site, when, why, etc

//************** settings *******************//

//Flag variable for site status

//Admin contact address;

//site URL(base for all redirections);

//location of the mysql connection script

//adjust the time zone for PHP5.1 and greeter


//********error management************//

//create the error handler
function my_error_handler ($e_number,$e_message,$e_file,$e_line,$e_vars){

//build error message
$message = "<p>An error occurred in script '$e_file' on line $e_line:$e_message\n<br/>";

//add date and time
$message .= "Date/Time: ".date('n-j-Y H:i:s')."\n<br/>";

//Append $e_vars to the $message
$message .= "<pre>".print_r($e_vars,1)."</pre>\n</p>";

if(!LIVE) {//Development (print the error)

echo'<div class="error">'.$message.'</div><br/>';

}else{//don't show the error;

//send an email to the admin;
mail(EMAIL,'Site Error!',$message,'From:email@example.com');

//only print an error message if the error isn't a notice
if($e_number != E_NOTICE){

echo'<div id="Error">A system error occurred. We apologize for the inconvenience.</div><br/>';

}// end of !LIVE if

}//end of my_error_handler

//*********************error management**************************//


<index page>

<?php #script 16.5 - index.php
// this is the main page for the site

//include the configuration file;

//set the page title and include the HTML header
$page_title = 'Welcome to this Site!';

//welcome the user (by name if they are logged in);
if(isset($_SESSION['first_name'])) {


<p>Thank you for visiting our website. It's our previlige to share lots of information with you, today! Blar Blar Blar... Blar. Blar...</p>
<p>Blar Blar Blar Blar Blar Bla rBlar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar Blar</p>

<?php //include the HTML footer file;


Thanks again and look forward to hearing from you soon.
  • 0

#2 jorgeLP



  • Members
  • PipPip
  • 39 posts
  • Locationreading, Pennsylvania, U.S

Posted 16 June 2011 - 10:03 AM

Hi Ryan, it look like you are sending something to the browser before the session_start() function. Remember you can not have any space at the beginning of the of your page tags, HTML, PHP. Go to
and see if there is a white space at the beginning of the you HTML tag or PHP tag and if there aren't none it could be your php.ini configuration. There are two different php.ini file, development and production environment. The production environment is what you want in when you move your site to you server.
  • 1