1

我有一些在在线购物车中使用的 PHP 代码我的问题是,当我尝试运行该页面时,它似乎在大多数情况下都可以正常工作,但页面没有显示总金额(运费加上产品成本) ) 而是显示一条错误消息,内容为

已弃用:在第 230 行 //index2.php已弃用调用时传递引用

我的完整 index.php 文件看起来像这样

    require_once('includes/config.inc.php');
$today = date('Y-m-d');
$coupon_code = urldecode($_POST['coupon_code']);

//$shipping_type = urldecode($_POST['shipping_type']);
$shipping_admin_zip = urldecode($_POST['shipping_admin_zip']);
$shipping_user_zip = urldecode($_POST['shipping_user_zip']);
$shipping_method = urldecode($_POST['shipping_method']);
$hid_product_weight = urldecode($_POST['hid_product_weight']);

$total = $m->getCartDetails($session_id);
$item_purchased = $total['total_product_qty'];
$payment_amount = $total['total_price'];

// CALULATE COUPON
$sql = "SELECT coupon_type,coupon_price,coupon_discount,coupon_code FROM `tbl_coupon` WHERE `coupon_code`='".$coupon_code."' AND '".$today."' BETWEEN `startdate` AND `expirydate`";
$coupon_res = $db->get($sql,__FILE__,__LINE__);
if($db->num_rows($coupon_res) > 0)
{
    $coupon_row = $db->fetch_array($coupon_res);
    $coupon_type = $coupon_row['coupon_type'];
    if(isset($coupon_row['coupon_type']) && $coupon_row['coupon_type']=="Price")
    {
        $coupon_price = $coupon_row['coupon_price'];
    }
    else if(isset($coupon_row['coupon_type']) && $coupon_row['coupon_type']=="Percentage")
    {
        $coupon_discount = $coupon_row['coupon_discount'];
    }
}
else
{
    if(empty($coupon_code)==false)
    {
        $msg_coupon = "Invalid Coupon code";
    }
}

// CALULATE TOTAL BY COUPON
if(isset($coupon_type) && empty($coupon_type)==false)
{
    if($coupon_type=="Price")
    {
        $coupon_price = round($coupon_price);
        $payment_amount = round(($payment_amount-$coupon_price),2);
    }
    else if($coupon_type=="Percentage")
    {
        $coupon_price = ($coupon_discount/100 * $payment_amount);
        $payment_amount = round(($payment_amount-$coupon_price),2);
    }   
}

//ZIP CODE CHECKING
if(empty($shipping_user_zip)==false)
{
    $sql_zip = "SELECT zip_code FROM `tbl_zip_code` WHERE `zip_code`='".$shipping_user_zip."'";
    $zip_res = $db->get($sql_zip,__FILE__,__LINE__);
    if($db->num_rows($zip_res) <= 0)
    {
        $msg_zip = "Invalid Zip code";
    }
}



/** 
    UPS PRODUCT CODE (this should be in a drop down menu) 
        Next Day Air Early AM    1DM 
        Next Day Air            1DA 
        Next Day Air Saver        1DP 
        2nd Day Air AM            2DM 
        2nd Day Air                2DA 
        3 Day Select            3DS 
        Ground                    GND 
        Canada Standard            STD 
        Worldwide Express        XPR 
        Worldwide Express Plus    XDM 
        Worldwide Expedited        XPD 

    UPS RATE CHART 
        Regular+Daily+Pickup 
        On+Call+Air 
        One+Time+Pickup 
        Letter+Center 
        Customer+Counter 

    Container Chart 
        Customers Packaging        00 

        UPS Letter Envelope        01 
        or 
        UPS Tube 

        UPS Express Box            21 
        UPS Worldwide 25kg Box    22 
        UPS Worldwide 10 kg Box    23 

    ResCom UPS Table 
        Residential                1 
        Commercial                2 
*/ 
class ups 
{ 
    var $_action; 
    var $_delivery_code; 
    var $_src_zip; 
    var $_dst_zip; 
    var $_weight; 
    var $_src_country; 
    var $_dst_country; 
    var $_rate_chart; 
    var $_rate_charts; 
    var $_container; 
    var $_containers; 
    var $_rescom; 
    var $_rescoms; 
    var $_errors; 

    function ups() 
    { 
       $this->_errors = array(); 
       $this->_action = 3; 
       $this->_delivery_code = 'GND'; 
       $this->_src_country = 'US'; 
       $this->_dst_country = 'US'; 
       $this->_rate_chart = 1; 
       $this->_container = '21'; 
       $this->_rescom = 1; 
       $this->_rate_charts = array('Regular+Daily+Pickup', 
                             'On+Call+Air', 
                             'One+Time+Pickup', 
                             'Letter+Center', 
                             'Customer+Counter'); 
       $this->_containers = array ('00', '01', '21', '22', '23', '1', '2'); 
       $this->_rescoms = array ('1', '2'); 

    } 
    function set_rescom ($int) 
    { 
       $this->_rescom = $int; 
    } 
    function set_container ($int) 
    { 
       $this->_container = $int; 
    } 
    function set_rate_chart($int) 
    { 
       $this->_rate_chart = 1; 
    } 
    function set_action($int) 
    { 
       $this->_action = $int; 
    } 
    function set_delivery_code ($code) 
    { 
       $this->_delivery_code = $code; 
    } 
    function set_src_zip ($zip) 
    { 
       $this->_src_zip = $zip; 
    } 
    function set_dst_zip ($zip) 
    { 
       $this->_dst_zip = $zip; 
    } 
    function set_src_country ($code) 
    { 
       $this->_src_country = $code; 
    } 
    function set_dst_country ($code) 
    { 
       $this->_dst_country = $code; 
    } 
    function set_weight ($int) 
    { 
       $this->_weight = $int; 
    } 
    function get_cost () 
    { 
       if ($this->_action == '') 
          array_push ($this->_errors, 'UPS Action is not defined'); 
       if ($this->_delivery_code == '') 
          array_push ($this->_errors, 'UPS Product Code is not defined'); 
       if ($this->_src_zip == '') 
          array_push ($this->_errors, 'Source Zip Code is unavailable'); 
       if ($this->_src_country == '') 
          array_push ($this->_errors, 'Source Country Code is unavailable'); 
       if ($this->_dst_zip == '') 
          array_push ($this->_errors, 'Destination Zip Code is unavailable'); 
       if ($this->_dst_country == '') 
          array_push ($this->_errors, 'Destination Country Code is unavailable'); 
       if ($this->_weight == '') 
          array_push ($this->_errors, 'Packet weight is not defined'); 
       if ($this->_rate_chart == '') 
          array_push ($this->_errors, 'Rate Chart is not defined'); 
       if ($this->_container == '') 
          array_push ($this->_errors, 'Client Shipping Package Type is not defined'); 
       if ($this->_rescom == '') 
          array_push ($this->_errors, 'Residential or Commercial? define it first!'); 
       if (count ($this->_errors) <= 0) 
       { 
          $url  = 'www.ups.com'; 
          $port = '80'; 
          $file = '/using/services/rave/qcostcgi.cgi'; 
          $qs   = '?'; 
          $qs  .= 'accept_UPS_license_agreement=yes'; 
          $qs  .= '&'; 
          $qs  .= '10_action='.$this->_action; 
          $qs  .= '&'; 
          $qs  .= '13_product='.$this->_delivery_code; 
          $qs  .= '&'; 
          $qs  .= '14_origCountry='. $this->_src_country; 
          $qs  .= '&'; 
          $qs  .= '15_origPostal='. $this->_src_zip; 
          $qs  .= '&'; 
          $qs  .= '19_destPostal='. $this->_dst_zip; 
          $qs  .= '&'; 
          $qs  .= '22_destCountry='. $this->_dst_country; 
          $qs  .= '&'; 
          $qs  .= '23_weight='. $this->_weight; 
          $qs  .= '&'; 
          $qs  .= '47_rateChart='.$this->_rate_charts[$this->_rate_chart]; 
          $qs  .= '&'; 
          $qs  .= '48_container='.$this->_rate_containers[$this->_rate_container]; 
          $qs  .= '&'; 
          $qs  .= '49_residential='.$this->_rescoms[$this->_rescom]; 
          $rqs  = $file.$qs; 
           $fp = @fsockopen ($url, 80, &$errno, &$errstr, 30); 
           if (!$fp) array_push ($this->_errors, 'Could not open socket'); 
          else 
          { 
             fputs($fp,"GET $rqs HTTP/1.0\n\n"); 
             while(!feof($fp)) 
             { 
                $buffer = fgets ($fp, 1024); 
                if (strpos ($buffer, '%')) 
                { 
                    $buffers = explode ('%', $buffer, -1); 
                    $errcode = substr ($buffers[0], -1); 
                    $goodcodes = array ('3', '4', '5', '6'); 
                    if (in_array ($errcode, $goodcodes)) 
                    { 
                       $cost = trim ($buffers[8]); 
                       return $cost; 
                    } 
                    else array_push ($this->_errors, 'Bad Result'); 
                } 
             } 
             fclose($fp); 
          } 
       } 
    } 
}
$ups = new ups;
$ups->set_rescom(2);
$ups->set_delivery_code($shipping_method);
$ups->set_src_zip($shipping_admin_zip); 
$ups->set_dst_zip($shipping_user_zip); 
$ups->set_weight ($hid_product_weight); 
$ups_cost = $ups->get_cost(); 

if(empty($coupon_price)==true)
{
    $coupon_price='0.00';
}
if(empty($ups_cost)==true)
{
    $ups_cost='0.00';
}
$payment_amount = round(($payment_amount+$ups_cost),2);
echo $payment_amount."~".$ups_cost."~".$coupon_price."~".$item_purchased."~".$coupon_code."~".$msg_coupon."~".$msg_zip;


// total price - shipping price - coupon price - total item - coupon code - Invalid coupon - Invalid Zip

/*if (!$ups_cost) 
    print_r ($ups->_errors)."~".$item_purchased."~".$payment_amount; 
else 
    print $ups_cost."~".$item_purchased."~".$payment_amount."~".$coupon_price;*/ 
4

1 回答 1

4

这行代码:

$fp = @fsockopen ($url, 80, &$errno, &$errstr, 30); 

正在请求$errno$errstr通过引用传递。较新版本的 PHP 要求函数的定义定义哪些参数通过引用传递,并且不赞成让调用者这样做。fsockopen已经将这些参数定义为传递引用,因此要修复它,请删除&s:

$fp = @fsockopen ($url, 80, $errno, $errstr, 30); 
于 2013-05-26T00:15:11.717 回答