【发布时间】:2012-05-29 15:14:21
【问题描述】:
首先,我是 php sysql 和数据库的新手。我确实知道一点 c++,所以这对 php 有帮助。我不太了解数据库,所以我的问题是:.....
这是我的代码:
<?php
echo $_SERVER['DOCUMENT_ROOT'].'/'.'lensClensProducts/views/layouts/'.$controller.'.php';
// Includes our database functions
include('db_functions.php');
// includes our cart functions
include('cart_fns.php');
session_start();
// set up default cart values
if(!isset($_SESSION['cart']))
{
$_SESSION['cart'] = array();
$_SESSION['total_items'] = 0;
$_SESSION['total_price'] = '0.00';
}
// Defaults to index view unless user requests different view
$view = empty($_GET['view']) ? 'index' : $_GET['view'];
// Used for layout
$controller = 'shop';
// checks which view is requested by user.
switch ($view) {
case "index":
$products = find_products();
break;
case "add_to_cart":
$id = $_GET['id'];
$add_item = add_to_cart($id);
$_SESSION['total_items'] = total_items($_SESSION['cart']);
$_SESSION['total_price'] = total_price($_SESSION['cart']);
header('Location: index.php');
break;
case "update_cart":
update_cart();
$_SESSION['total_items'] = total_items($_SESSION['cart']);
$_SESSION['total_price'] = total_price($_SESSION['cart']);
header('Location: index.php?view=checkout');
break;
case "checkout":
if ( 0 < $_SESSION['total_price'] && $_SESSION['total_price'] <= 100 )
{
$shipping = 11.95;
}
if ( 100 < $_SESSION['total_price'] && $_SESSION['total_price'] <= 250 )
{
$shipping = 18.50;
}
if ( 250 < $_SESSION['total_price'] && $_SESSION['total_price'] <= 500 )
{
$shipping = 25.50;
}
if ( 500 < $_SESSION['total_price'] && $_SESSION['total_price'] <= 1000 )
{
$shipping = 36.00;
}
if ( 1000 < $_SESSION['total_price'] && $_SESSION['total_price'] <= 2500 )
{
$shipping = 64.50;
}
else if ( 2500 < $_SESSION['total_price'] )
{
$shipping = 250.00;
}
break;
}
// includes layout for controller
include( $_SERVER['DOCUMENT_ROOT'].'/'.'lensClensProducts/views/layouts/'.$controller.'.php' );
?>
最后一行 include($_SERVER['DOCUMENT_ROOT'].'/'.'gamelist/views/layouts/'.$controller.'.php' ); 有问题;
PS 在这段代码的第 16 行还有一个回显
特别是 ['DOCUMENT_ROOT'] 我猜这是一个全局变量。
我是这个出现的本地主机并且工作正常,在 go daddy 中这没有做任何事情,只是给我一个错误
警告:session_start() [function.session-start]:无法发送会话 cookie - 标头已由(输出开始于 /home/content/27/6235127/html/gamelist/index.php:4)在 / home/content/27/6235127/html/gamelist/index.php 在第 16 行
警告:session_start() [function.session-start]:无法发送会话缓存限制器 - 标头已发送(输出开始于 /home/content/27/6235127/html/gamelist/index.php:4)在 /第 16 行的 home/content/27/6235127/html/gamelist/index.php /gamelist/views/layouts/index.php
我怀疑这与服务器名称有关,我使用了 lensclens3.db.6235127.hostedresource.com 的服务器名称,但不起作用。
我知道上面的这个服务器名称在这个购物车的另一个页面上使用(和工作)时有效。
我应该使用其他服务器名称吗?
【问题讨论】:
-
Headers already sent by PHP 的可能重复项