Jump to content


Photo

Small problem with plaincart php


  • Please log in to reply
5 replies to this topic

#1 Mark Hammill

Mark Hammill

    Young Padawan

  • Members
  • Pip
  • 5 posts
  • Location:Swansea, South Wales, UK
  • Interests:Chocolate

Posted 11 February 2008 - 09:17 AM

Hi,

I have almost finished my first webpage with php but I have an error I can't manage to fix.

I used the plaincart template to start with.

If you go to www.michton.com/shop.php

There is an error at the top of the page, it is on black so you need to highlight it.

The error is:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/mark1471/public_html/shop.php:6) in /home/mark1471/public_html/library/config.php on line 3

Does anyone know how to fix this.

I'm not sure what information would help but I've inluded some code below.

Thanks in advance



shop.php

<?php
require_once 'library/config.php';
require_once 'library/category-functions.php';
require_once 'library/product-functions.php';
require_once 'library/cart-functions.php';
$_SESSION['shop_return_url'] = $_SERVER['REQUEST_URI'];
$catId = (isset($_GET['c']) && $_GET['c'] != '1') ? $_GET['c'] : 0;
$pdId = (isset($_GET['p']) && $_GET['p'] != '') ? $_GET['p'] : 0;
require_once 'include/header.php';
?>


config.php

<?php
ini_set('display_errors', 'On');
//ob_start("ob_gzhandler");
error_reporting(E_ALL);

// start the session
session_start();

// database connection config
$dbHost = 'localhost';
$dbUser = 'mark1471_michton';
$dbPass = 'nottelling;
$dbName = 'mark1471_plaincart';

// setting up the web root and server root for
// this shopping cart application
$thisFile = str_replace('\\', '/', __FILE__);
$docRoot = $_SERVER['DOCUMENT_ROOT'];

$webRoot = str_replace(array($docRoot, 'library/config.php'), '', $thisFile);
$srvRoot = str_replace('library/config.php', '', $thisFile);

define('WEB_ROOT', $webRoot);
define('SRV_ROOT', $srvRoot);

// these are the directories where we will store all
// category and product images
define('CATEGORY_IMAGE_DIR', 'images/category/');
define('PRODUCT_IMAGE_DIR', 'images/product/');

// some size limitation for the category
// and product images

// all category image width must not
// exceed 220 pixels
define('MAX_CATEGORY_IMAGE_WIDTH', 110);

// do we need to limit the product image width?
// setting this value to 'true' is recommended
define('LIMIT_PRODUCT_WIDTH', true);

// maximum width for all product image
define('MAX_PRODUCT_IMAGE_WIDTH', 300);

// the width for product thumbnail
define('THUMBNAIL_WIDTH', 110);

if (!get_magic_quotes_gpc()) {
if (isset($_POST)) {
foreach ($_POST as $key => $value) {
$_POST[$key] = trim(addslashes($value));
}
}

if (isset($_GET)) {
foreach ($_GET as $key => $value) {
$_GET[$key] = trim(addslashes($value));
}
}
}

// since all page will require a database access
// and the common library is also used by all
// it's logical to load these library here
require_once 'database.php';
require_once 'common.php';

// get the shop configuration ( name, addres, etc ), all page need it
$shopConfig = getShopConfig();
?>

Edited by Mark Hammill, 11 February 2008 - 09:20 AM.


#2 curthard89

curthard89

    Young Padawan

  • Members
  • Pip
  • 226 posts

Posted 13 February 2008 - 04:02 AM

"headers already sent" means sumthing has been printed onto the page before the headers trying to do sumthing, headers only work if nothing has been outputted, check your code :P

#3 shameless_w_o_a_d

shameless_w_o_a_d

    Young Padawan

  • Members
  • Pip
  • 42 posts
  • Gender:Male
  • Location:New Zealand
  • Interests:Web Design, Graphics Design, Computers, Games, Music, Basketball

Posted 14 February 2008 - 04:47 AM

In the config.php page, move the session_start() function to the top. Both the ini_set() and error_reporting() functions are causing that warning to occur, as they both return some form of output upon success, hence the warning.

Otherwise, use ob_start() and ob_flush() respectively to wrap those lines to allow the headers to be sent whilst still having output contained in the buffer until it is released (flushed) if you'd prefer to keep the lines the same.

#4 Mark Hammill

Mark Hammill

    Young Padawan

  • Members
  • Pip
  • 5 posts
  • Location:Swansea, South Wales, UK
  • Interests:Chocolate

Posted 14 February 2008 - 05:51 AM

Hi, I have tried changing the code but still no improvement.

I have changed the config.php to the following and uploaded it.

<?php
//start the session
session_start();

// database connection config
$dbHost = 'localhost';
$dbUser = 'mark1471_michton';
$dbPass = 'hidden';
$dbName = 'mark1471_plaincart';

Edited by Mark Hammill, 14 February 2008 - 05:52 AM.


#5 shameless_w_o_a_d

shameless_w_o_a_d

    Young Padawan

  • Members
  • Pip
  • 42 posts
  • Gender:Male
  • Location:New Zealand
  • Interests:Web Design, Graphics Design, Computers, Games, Music, Basketball

Posted 15 February 2008 - 12:31 AM

Ahh, I believe I see the problem now. :D

The reason is because while the line is the first line in the config.php file, you are including the config.php file which essentially is outputting data before the header.

Start your session in the shop.php file and place it above the require lines. That should fix your issues.

Edited by shameless_w_o_a_d, 15 February 2008 - 12:33 AM.


#6 Mark Hammill

Mark Hammill

    Young Padawan

  • Members
  • Pip
  • 5 posts
  • Location:Swansea, South Wales, UK
  • Interests:Chocolate

Posted 15 February 2008 - 04:15 AM

It works.

Thank you for all your help.

I have other code before the php section on the shop page.

Now it works a treat.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users