Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2010
    Posts
    53
    Plugin Contributions
    0

    help question help with my php code

    Hi,
    Recently I am try to do some programming work.
    I want my Zen Cart store to update tracking information to the online system of our shipping agency.
    I got strange problem.
    I installed in my local PC:
    Apache 2.2.9
    PHP 5.2.6
    MySQL 5.1.28&4.0.26

    I also install a zencart in my local PC.
    I ran the following track.php file in my PC:
    PHP Code:
    <?php
    echo "hi";
    var_dump(esp_track_result('10465708'));

    function 
    esp_track_result($sn){
    $url         "http://api.espeedpost.com/track/";
    $devid     "EspeedPost";
    $appid     "80010616-XXXXXXXXXXXX";
    if (
    $sn != '')
        {
        
    $string = array
        (
        
    "devid" => $devid,
        
    "appid" => $appid,
        
    "cus_name" => "no",
        
    "cus_value" => $sn,
        );

        
    $content Post($url$string);  
        
        
        
        
    $objXmlToArray=new xmlToArray();
        
    $objXmlToArray->parseString($content);
        
    $data $objXmlToArray->getTree();
        
    //print_r($data);
        
    $objXmlToArray->free();

        
    //提取查询信息
        
    $result $data[GetTrackingInformation][Result][value];

        if (
    $result == "Success"){
        
    //echo "The latest status of parcel ".$data[GetTrackingInformation][ParcelNumber][value]." is ".$data[GetTrackingInformation][ParcelInfo][LastStatusContent][value]." at ".$data[GetTrackingInformation][ParcelInfo][LastDateTime][value]."\n";
        //echo "AAAAAA";
        
    return $data[GetTrackingInformation][ParcelNumber][value];
        }
        if (
    $result == "Failure"){
        
    //echo $data[GetTrackingInformation][Reason][value]."\n";
        //echo "BBBBBBB";
        
    return false;
        }
        
        
        }

    }
    ////////////////////////////////////////////////////////

    ///////////////////////////////////////////////////////
    function Post($url$post null)
    {  
    $context = array();  
      
    if (
    is_array($post))    
        {  
        
    ksort($post);  
        
    $context["http"] = array
            (  
            
    "method" => "POST",  
            
    "content" => http_build_query($post"""&"),  
            );  
        }  
        return 
    file_get_contents($urlfalsestream_context_create($context));  
    }

    //////////////////////////////////////////////////////
    function urlvalue($urlname)
    {
    $urlvalue = !empty($_POST[$urlname]) ? $_POST[$urlname] : $_GET[$urlname];
    return 
    $urlvalue;
    }

    //////////////////////////////////////////////////////////
    class xmlToArray
    {
        var 
    $parser;
       
        
    /**
        * source encoding
        *
        * @var string
        */
        
    var $srcenc;
       
        
    /**
        * target encoding
        *
        * @var string
        */
        
    var $dstenc;
       
        
    /**
        * the original struct
        *
        * @access private
        * @var array
        */
        
    var $_struct = array();
       
        
    /**
        * Constructor
        *
        * @access public
        * @param mixed [$srcenc] source encoding
        * @param mixed [$dstenc] target encoding
        * @return void
        * @since
        */
        
    function xmlToArray($srcenc null$dstenc null)
        {
            
    $this->srcenc $srcenc;
            
    $this->dstenc $dstenc;
           
            
    // initialize the variable.
            
    $this->parser null;
            
    $this->_struct = array();
        }
       
        
    /**
        * 释放资源
        *
        * @access public
        * @return void
        **/
        
    function free()
        {
            if (isset(
    $this->parser) && is_resource($this->parser))
            {
                
    xml_parser_free($this->parser);
                unset(
    $this->parser);
            }
        }
       
        
    /**
        * 解析XML文件
        *
        * @access public
        * @param string [$file] the XML file name
        * @return void
        * @since
        */
        
    function parseFile($file)
        {
            
    $data = @file_get_contents($file) or die("Can't open file $file for reading!");
            
    $this->parseString($data);
        }
       
        
    /**
        * 解析XML字符串
        *
        * @access public
        * @param string [$data] XML data
        * @return void
        */
        
    function parseString($data)
        {
            if (
    $this->srcenc === null)
            {
                
    $this->parser = @xml_parser_create() or die('Unable to create XML parser resource.');
            }
            else
            {
                
    $this->parser = @xml_parser_create($this->srcenc) or die('Unable to create XML parser resource with '$this->srcenc .' encoding.');
            }
           
            if (
    $this->dstenc !== null)
            {
                @
    xml_parser_set_option($this->parserXML_OPTION_TARGET_ENCODING$this->dstenc) or die('Invalid target encoding');
            }
            
    xml_parser_set_option($this->parserXML_OPTION_CASE_FOLDING0); // lowercase tags
            
    xml_parser_set_option($this->parserXML_OPTION_SKIP_WHITE1); // skip empty tags
            
    if (!xml_parse_into_struct($this->parser$data, &$this->_struct))
            {
                
    printf("XML error: %s at line %d",
                
    xml_error_string(xml_get_error_code($this->parser)),
                
    xml_get_current_line_number($this->parser)
            );
            
    $this->free();
            exit();
            }
           
            
    $this->_count count($this->_struct);
            
    $this->free();
        }
       
        
    /**
        * 返回解析完毕后的XML数组
        *
        * @access public
        * @return array
        */
        
    function getTree()
        {
            
    $i 0;
            
    $tree = array();
           
            
    $tree $this->addNode(
                
    $tree,
                
    $this->_struct[$i]['tag'],
                (isset(
    $this->_struct[$i]['value'])) ? $this->_struct[$i]['value'] : '',
                (isset(
    $this->_struct[$i]['attributes'])) ? $this->_struct[$i]['attributes'] : '',
                
    $this->getChild($i)
            );
           
            unset(
    $this->_struct);
        return (
    $tree);
        }
       
        
    /**
        * recursion the children node data
        *
        * @access public
        * @param integer [$i] the last struct index
        * @return array
        */
        
    function getChild(&$i)
        {
        
    // contain node data
        
    $children = array();
       
        
    // loop
        
    while (++$i $this->_count)
        {
        
    // node tag name
        
    $tagname $this->_struct[$i]['tag'];
        
    $value = isset($this->_struct[$i]['value']) ? $this->_struct[$i]['value'] : '';
        
    $attributes = isset($this->_struct[$i]['attributes']) ? $this->_struct[$i]['attributes'] : '';
       
        switch (
    $this->_struct[$i]['type']) {
        case 
    'open':
        
    // node has more children
        
    $child $this->getChild($i);
        
    // append the children data to the current node
        
    $children $this->addNode($children$tagname$value$attributes$child);
        break;
        case 
    'complete':
        
    // at end of current branch
        
    $children $this->addNode($children$tagname$value$attributes);
        break;
        case 
    'cdata':
        
    // node has CDATA after one of it's children
        
    $children['value'] .= $value;
        break;
        case 
    'close':
        
    // end of node, return collected data
        
    return $children;
        break;
        }
       
        }
        
    //return $children;
        
    }
       
            
    /**
            * Appends some values to an array
            *
            * @access public
            * @param array [$target]
            * @param string [$key]
            * @param string [$value]
            * @param array [$attributes]
            * @param array [$inner] the children
            * @return void
            * @since
            */
            
    function addNode($target$key$value ''$attributes ''$child '')
            {
                if (!isset(
    $target[$key]['value']) && !isset($target[$key][0]))
                {
                    if (
    $child != '')
                    {
                        
    $target[$key] = $child;
                    }
                    if (
    $attributes != '')
                    {
                        foreach (
    $attributes as $k => $v)
                        {
                        
    $target[$key][$k] = $v;
                        }
                    }
               
                    
    $target[$key]['value'] = $value;
                }
                else
                {
                    if (!isset(
    $target[$key][0]))
                    {
                        
    // is string or other
                        
    $oldvalue $target[$key];
                        
    $target[$key] = array();
                        
    $target[$key][0] = $oldvalue;
                        
    $index 1;
                    }
                    else
                    {
                        
    // is array
                        
    $index count($target[$key]);
                    }
               
                    if (
    $child != '') {
                    
    $target[$key][$index] = $child;
                    }
               
                    if (
    $attributes != '') {
                    foreach (
    $attributes as $k => $v) {
                    
    $target[$key][$index][$k] = $v;
                    }
                    }
                    
    $target[$key][$index]['value'] = $value;
                }
                return 
    $target;
            }
    }

    //////////////////////////////////////////////////////////////////////
    ?>
    Everything works fine. I could get reply.
    However, I upload the code to my server:
    Apache version 2.2.26
    PHP version 5.2.17
    MySQL version 5.5.36-log

    The php could not run. I got nothing on my browser. Even the first code replying "hi" seems not work. Nothing replied even error indication.
    I also wrote other php files and they all could run.
    Any ideal what 's wrong?
    Thanks for your time.

  2. #2
    Join Date
    Apr 2007
    Location
    Ontario, Canada
    Posts
    1,732
    Plugin Contributions
    27

    Default Re: help with my tracking code in Zencart

    Which page are you calling the track.php file from in Zen Cart?
    Twitch.
    https://www.twitchtoo.com Do you work for free? Please donate.
    June 7.2026 - NOW AVAILABLE - Twitch Base8 - Obsidian

  3. #3
    Join Date
    Apr 2010
    Posts
    53
    Plugin Contributions
    0

    Default Re: help with my tracking code in Zencart

    I visited this page from browser directly, not called from other page.

  4. #4
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: help with my tracking code in Zencart

    Quote Originally Posted by wilsonshen View Post
    I visited this page from browser directly, not called from other page.
    Can't say from just looking at it that there is any particularly special line of code, but are the same add-ons enabled on the server in php.ini as on local computer?

    Do you have access to the server error logs to identify what the server thinks is wrong? The way it is written, ZC won't generate any error, because at the moment it is independent of ZC (or so it appears). Also may want to see if any of the functions used (again, didn't see any that were special while scrolling through) have been deprecated in the more recent version of PHP on the server. Check the php manual for that as a source.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 

Similar Threads

  1. v153 php help with Password Min_length code change
    By rebecca_L in forum General Questions
    Replies: 5
    Last Post: 15 Apr 2015, 04:12 AM
  2. v150 Help with Merging PHP Code
    By Johnnycopilot in forum Templates, Stylesheets, Page Layout
    Replies: 14
    Last Post: 16 Mar 2015, 07:30 PM
  3. Desperatley Need Help with PHP / MYSQL code
    By philip937 in forum General Questions
    Replies: 19
    Last Post: 7 Oct 2009, 06:47 PM
  4. Basic mysql/php code with Zen help?
    By laurenjj in forum General Questions
    Replies: 3
    Last Post: 29 May 2009, 01:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg