PDA

View Full Version : session_start(); error


crazyfish
April 3rd, 2006, 02:29
Take a look at this page and the error I am getting: http://myerstowing.com/invent/

Before I intregrated this script into the site I would not receive the error. But as soon as I added it into the site the error started popping and I can't figure out why.

This is the page it is referring to:


<?
session_start();

error_reporting(0);

require_once _LIBPATH . "common.php";
require_once _LIBPATH . "xml.php";
require_once _LIBPATH . "template.php";
require_once _LIBPATH . "config.php";
require_once _LIBPATH . "html.php";
require_once _LIBPATH . "database.php";
require_once _LIBPATH . "vars.php";
require_once _LIBPATH . "menu.php";
require_once _LIBPATH . "library.php";
require_once _LIBPATH . "sqladmin.php";
require_once _LIBPATH . "forms.php";
require_once _LIBPATH . "mail.php";

class CBase {
/**
* description
*
* @var type
*
* @access type
*/
var $html;

}
class CSite {

/**
* description
*
* @var type
*
* @access type
*/
var $admin;
/**
* description
*
* @var type
*
* @access type
*/
var $html;


/**
* description
*
* @param
*
* @return
*
* @access
*/
function CSite($xml , $admin = false) {
global $_CONF , $base;

$this->admin = $admin;

//loading the config
$tmp_config = new CConfig($xml);

$_CONF = $tmp_config->vars["config"];

//loading the templates
if ($this->admin) {
if (is_array($_CONF["templates"]["admin"])) {
foreach ($_CONF["templates"]["admin"] as $key => $val) {
if ($key != "path")
$this->templates[$key] = new CTemplate($_CONF["templates"]["admin"]["path"] . $_CONF["templates"]["admin"][$key]);
}
}
} else {

if (is_array($_CONF["templates"])) {
foreach ($_CONF["templates"] as $key => $val) {
if (($key != "path" ) && ($key != "admin"))
$this->templates[$key] = new CTemplate($_CONF["templates"]["path"] . $_CONF["templates"][$key]);
}
}
}


$base = new CBase();
$base->html = new CHtml();
$this->html = &$base->html;

//make a connection to db
if (is_array($_CONF["database"])) {
$this->db = new CDatabase($_CONF["database"]);

//vars only if needed
if ($_CONF["tables"]["vars"]) {
$this->vars = new CVars($this->db , $_CONF["tables"]["vars"]);
$base->vars = &$this->vars;
}

$this->tables = &$_CONF["tables"];
}

}

function TableFiller($item) {
if (file_exists("pb_tf.php")) {
include("pb_tf.php");
}
}

/**
* description
*
* @param
*
* @return
*
* @access
*/
function Run() {
global $_TSM;

if (file_exists("pb_events.php")) {
include("pb_events.php");

$_TSM["PB_EVENTS"] = @DoEvents($this);
}

if (is_object($this->templates["layout"])) {
echo $this->templates["layout"]->Replace($_TSM);
}
}
}


?>


All I did was take what was in the index.php file of the script and pasted the code into the sites template and thats when the error started.


<?php

require "config.php";

$_PAGE = "index";

$site = new CSite("admin/site.xml");
$site->Run();
?>


Any one have any ideas as to how to correct this? IE and FX give different error messages but refer to the same file and line number.

If I remove the start session then I can't log into the admin section.

Thanks
Nick

Dan
April 3rd, 2006, 02:59
That's because you can't use session_start after HTML has already been output.

The hacky way of fixing this would be to put <?php ob_start(); ?> before any code, then <?php ob_end_flush(); ?> at the very end.

crazyfish
April 3rd, 2006, 03:03
Thanks Dan. That worked.

Tyler
April 3rd, 2006, 04:04
<?
session_start();

I would HIGHLY suggest not to use shorttags. :)

Dan
April 3rd, 2006, 06:49
I'll be the devil's advocate today, so.. why not Tyler?

The only disadvantage I see to short_tags is that some systems have them disabled.

Personally I only use them in templates, since <?=$variable;?> is nice and compact.

crazyfish
April 3rd, 2006, 12:33
How come Tyler? I know zero about php coding so use small words and short sentences. :lol:

If I remove the session start I am unable to use the admin section. I have no clue what would need to be removed or added to get that working. If the session start is removed what would be using it to allow me to login to the admin section?

jos
April 3rd, 2006, 14:08
To answers Dan's question: writing according to PEAR coding standards.

Always use <?php ?> to delimit PHP code, not the <? ?> shorthand. This is required for PEAR compliance and is also the most portable way to include PHP code on differing operating systems and setups.

<?
session_start();

I would HIGHLY suggest not to use shorttags. :)

To answer crazyfish's question: Tyler is talking about the <? tag, not the sessionstart();. The <? tag opens php but <?php is prefered.

If I remove the session start I am unable to use the admin section. I have no clue what would need to be removed or added to get that working. If the session start is removed what would be using it to allow me to login to the admin section?

Which sorta answers this, removing the session_start(); would make no sense, because your whole admin system is based on sessions. If you would remove session_start(); you would have to rewrite your complete code :)

crazyfish
April 3rd, 2006, 14:29
Thanks Jos.

I should change it from <? session_start(); to <?php
session_start(); ?

jos
April 3rd, 2006, 14:58
yes

Tyler
April 3rd, 2006, 21:06
Yup, exactly as jos has said :) And IIRC PHP5 had it turned off by default, so many servers doesn't have it sat up. You never want to get in any bad habits, take it from me! And there was talk about removing them completely from PHP6, I'm not too sure about that outcome...

crazyfish
April 3rd, 2006, 21:08
Thanks Tyler. Makes sense now. As for me and making it a bad habit I would have to have a clue about what I was doing first to make it a bad habit. :lol:

Dan
April 3rd, 2006, 22:33
And IIRC PHP5 had it turned off by defaultThis is going to be a PITA :)

crazyfish
April 3rd, 2006, 23:06
PITA??

Dan
April 3rd, 2006, 23:15
http://acronymfinder.com/af-query.asp?Acronym=PITA&Find=find&string=exact

crazyfish
April 3rd, 2006, 23:59
Pacific Islands Telecommunications Association????????? :lol:

jos
April 4th, 2006, 11:37
no, no... i think he meant People for the Intelligent Treatment of Animals