Jump to content
Larry Ullman's Book Forums

Recommended Posts

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

ob_start();

 

//initialize a session;

session_start();

 

//check for a $page_title value;

if(!isset($page_title)){

$page_title='User Registration';

}

 

?>

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<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";

</style>

 

</head>

 

<body>

<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

define('LIVE',FALSE);

 

//Admin contact address;

define('EMAIL','service@mascdesign.com');

 

//site URL(base for all redirections);

define('BASE_URL','http://www.ryan.divinehosting.ca//template-registration');

 

//location of the mysql connection script

define('MYSQL','../../mysqli_connect.php');

 

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

date_default_timezone_set('America/Toronto');

 

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

//************************************//

 

//************************************//

//********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;

require_once('includes/config.inc.php');

 

//set the page title and include the HTML header

$page_title = 'Welcome to this Site!';

include('includes/header.html');

 

//welcome the user (by name if they are logged in);

echo'<h1>Welcome';

if(isset($_SESSION['first_name'])) {

echo",{$_SESSION['first_name']}!";

}

echo'</h1>';

 

?>

 

<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;

include('includes/footer.html');

?>

 

--------------------------------------------------------------------------------------------------------------------------------------

 

Thanks again and look forward to hearing from you soon.

Link to comment
Share on other sites

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

/home/ryandivi/public_html/template-registration/includes/config.inc.php:69  

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.

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...