1

I have some PHP code that is used in an online shopping cart my issue is that when I try to run the page it seems to work for the most part with the exception that the page is not displaying a total amount (shipping cost plus product cost) and instead shows an error message that says

Deprecated: Call-time pass-by-reference has been deprecated in //index2.php on line 230

My full index.php file looks like this

    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;*/ 
Lion
  • 18,729
  • 22
  • 80
  • 110
Jayreis
  • 253
  • 1
  • 7
  • 28
  • 2
    If it is deprecated, it is deprecated. It means, you either need to downgrade your server, or upgrade your knowledge – samayo May 26 '13 at 00:13

1 Answers1

4

This line of code:

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

is requesting that $errno and $errstr be passed by reference. Newer versions of PHP require that the definition of the function define which parameters are passed by reference, and deprecate having the caller do that. fsockopen already defines those parameters as pass-by-reference, so to fix it, remove the &s:

$fp = @fsockopen ($url, 80, $errno, $errstr, 30); 
icktoofay
  • 126,289
  • 21
  • 250
  • 231
  • 1
    It should be noted that when the Documentation lists a function signature as `&$errno`, it means that the function itself accepts a variable reference. In other words, you MUST pass a variable (or nothing if it's an optional parameter and you're not passing any later arguments) as opposed to a literal value, and that variable will contain some data about the function's execution - in this case, any error conditions. It does NOT mean that you should manually pass the variable by reference. – Niet the Dark Absol May 26 '13 at 01:10