改一下變量名字 <? function Update() { global $_SESSION_sId,$_SESSION_sName,$_SESSION_sPirce, $_SESSION_sDiscount,$_SESSION_sGoodPrice, $_SESSION_sCount,$_SESSION_sMaxCount; if(!isset($_SESSION_sId) or !isset($_SESSION_sName) or !isset($_SESSION_sPrice) or !isset($_SESSION_sDiscount) or !isset($_SESSION_sMaxCount) or !isset($_SESSION_sGoodPrice) or !isset($_SESSION_sCount)) return;} ?>
没有看出来有什么错误! 但是你的这种用法好象有问题: php手册上说: If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered() and session_unregister(). 意思是说如果你使用$_SESSION或者$HTTP_SESSION_VARS,就不要使用那三个函数。 ------------ This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_SESSION; to access it within functions or methods, as you do with $HTTP_SESSION_VARS.
我查手册得到结果: Caution If you want your script to work regardless of register_globals, you need to use the $_SESSION array. All $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where register_globals is disabled. 看来是session变量自动创建了,在你需要的时候!to: hhzh426(春之风)非常感谢!!
<?
function Update()
{
global $_SESSION_sId,$_SESSION_sName,$_SESSION_sPirce,
$_SESSION_sDiscount,$_SESSION_sGoodPrice,
$_SESSION_sCount,$_SESSION_sMaxCount; if(!isset($_SESSION_sId) or !isset($_SESSION_sName) or !isset($_SESSION_sPrice)
or !isset($_SESSION_sDiscount) or !isset($_SESSION_sMaxCount)
or !isset($_SESSION_sGoodPrice) or !isset($_SESSION_sCount))
return;}
?>
它的意思是解析发生错误(第四行),应该是,或者;的地方出现了[。
$_SESSION好象是个超级变量,在任何函数中都不需要事先申明就可以直接使用。
在
global $_SESSION['sId'],$_SESSION['sName'],$_SESSION['sPirce'];
这一行!
我用了一个类,现在想修改成支持php4.30的。
class TCart
{
var $Id; //每类商品的ID(数组)
var $Name; //每类商品的名称(数组)
var $Price; //每类商品的价格(数组)
//******构造函数
function TCart()
{
$this->SortCount = 0; session_start(); //初始化一个session
session_register('sId');
session_register('sName');
session_register('sPrice');
session_register('sDiscount');
}//********私有,根据session的值更新类中相应数据
function Update()
{
global $_SESSION['sId'],$_SESSION['sName'],
$_SESSION['sPirce'];
if(!isset($_SESSION['sId']) or !isset($_SESSION['sName']) or !isset($_SESSION['sPrice']))
return;
......
}
在用之前先把session中的变量取出来再操作吧。
但是你的这种用法好象有问题:
php手册上说:
If you are using $_SESSION (or $HTTP_SESSION_VARS), do not use session_register(), session_is_registered() and session_unregister().
意思是说如果你使用$_SESSION或者$HTTP_SESSION_VARS,就不要使用那三个函数。
------------
This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_SESSION; to access it within functions or methods, as you do with $HTTP_SESSION_VARS.
数组中的元素不能作为函数的参数吗?
我也看到了,你有什么好的解决方法?
session_register('sId');
session_register('sName');
session_register('sPrice');
session_register('sDiscount');
改成:
$_SESSION['sId'] = array();
$_SESSION['sName'] = array();
$_SESSION['sPrice'] = array();
$_SESSION['sDiscount'] = "";---------
function Update()
{
if(empty($_SESSION['sId']) or empty($_SESSION['sName']) or empty($_SESSION['sPrice']))
return;
......
}session_start(); //初始化一个session
这一句最好不要放在类中进行调用,最好在脚本的开始部分调用。
我没有试过重复调用session_start()会不会出错!
Caution
If you want your script to work regardless of register_globals, you need to use the $_SESSION array. All $_SESSION entries are automatically registered. If your script uses session_register(), it will not work in environments where register_globals is disabled.
看来是session变量自动创建了,在你需要的时候!to: hhzh426(春之风)非常感谢!!