We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12379
    • 460 Posts
    Having trouble with an external configuration file linking to another configuration file within a MODx page.

    I’ve checked and rechecked my work but can’t find a solution to the following error:

    PHP error debug
    Error: require_once(../../../affiliates/lib/xmlrpc.inc) [function.require-once]: failed to open stream: No such file or directory
    Error type/ Nr.: Warning - 2
    File: /home/xxxx/public_html/assets/snippets/affiliatesforall/affiliatecart.inc
    Line: 24
    Line 24 source: require_once (’../../../affiliates/lib/xmlrpc.inc’);


    I have "affiliatecart_inc" snippet call the top of my page, http://www.xxxx.com.au/test/affiliates/sub?ref=2:

    <?php
    require_once($modx->config['base_path']."assets/snippets/affiliatesforall/affiliatecart.inc");
    ?>


    assets/snippets/affiliatesforall/affiliatecart.inc:

    <?php 
    (23) require_once ('config.inc'); /* No problem line */
    (24) require_once ('../../../affiliates/lib/xmlrpc.inc'); /* Problem line */
    (rest of code)
    


    I’ve tried various path combinations of the following to test if I’d missed anything:

    ../../../affiliates/lib/xmlrpc.inc
    ../../affiliates/lib/xmlrpc.inc
    ../affiliates/lib/xmlrpc.inc
    ./affiliates/lib/xmlrpc.inc
    /affiliates/lib/xmlrpc.inc
    affiliates/lib/xmlrpc.inc


    The MODx file structure is:

    /assets
    /snippets
    /affiliatesforall
    affiliatecart.inc
    config.inc


    The file that failed to be found is here:
    /affiliates
    /lib
    xmlrpc.inc


    Any clues out there please? (I realise config files ending in .inc only is poor form)
      Mostly harmless.
      • 22303 MODX Staff
      • 10,725 Posts
      Just make it absolute:
      require_once ($modx->config['base_path'] . 'affiliates/lib/xmlrpc.inc');

        • 12379
        • 460 Posts
        Thanks, but am now getting:


        PHP error debug
        Error: xmlrpc: (code 5) Connect error: php_network_getaddresses: getaddrinfo failed: Name or service not known (0)
        Error type/ Nr.: User Error - 256
        File: /home/xxxx/public_html/assets/snippets/affiliatesforall/affiliatecart.inc
        Line: 47
        Line 47 source: E_USER_ERROR);

          Mostly harmless.
          • 26903
          • 1,336 Posts
          OK, you’ve fixed your include problem, now you’ve got another prob. This error usually means you can’t resolve the site you are trying to find, ie a DNS error, it could also be other things depending on the network set up on your box. The following link is one of many on this subject :-
          http://www.ozoneasylum.com/5778
            Use MODx, or the cat gets it!
            • 12379
            • 460 Posts
            That’s weird. This script worked fine on on the same server but has shown this error since integrating parts into MODx...
              Mostly harmless.
              • 26903
              • 1,336 Posts
              If it has worked in the past using the same host as your using now it looks as though your DNS is OK.

              It may be then that the process of integration itself has broken it somehow, eg a variable being passed is now not set or some such.
                Use MODx, or the cat gets it!
                • 12379
                • 460 Posts
                How odd considering the way I’ve set it up in MODx is the equivalent of the working version.


                affiliatecart.inc:
                require_once ($modx->config['base_path'] . 'assets/snippets/affiliatesforall/config.inc');
                require_once ($modx->config['base_path'] . 'affiliates/lib/xmlrpc.inc');
                
                session_start();
                
                $xmlrpc_internalencoding = 'UTF-8';
                
                function affiliate_call($method, $params) {
                    global $rpc_secret, $affiliate_base;
                
                    array_unshift($params, new xmlrpcval($rpc_secret, 'string'));
                    $message = new xmlrpcmsg($method, $params);
                    $client = new xmlrpc_client("$affiliate_base/xmlrpc-cart.php");
                    $client->return_type = 'phpvals';
                
                    // If you want to see the xmlrpc interaction, uncomment the following line:
                    // $client->setDebug(2);
                
                    $result = $client->send($message);
                    if($result->faultCode()) {
                        trigger_error('xmlrpc: ' .
                            '(code ' . htmlentities($result->faultCode()) . ') ' .
                            htmlentities($result->faultString()),
                            E_USER_ERROR); //Line 47
                    } else {
                        return $result->value();
                    }
                }
                
                etc
                etc


                config.inc
                <?php
                
                // The following variable should be the URL of your affiliates' logon screen.
                
                $affiliate_base = 'http://www.xxxx.com.au/affiliates';
                
                $rpc_secret = 'changeme';
                
                ?>
                  Mostly harmless.
                  • 26903
                  • 1,336 Posts
                  You may be suffering from a scoping issue, the snippet code when included is ’evaled’ by MODx, this can lead to errors that you won’t see if you just run the script natively. I had a similar issue when I imported my site into MODx ages ago. I had to ’modxify’ some external php scripts before they would work. Its just a matter of debugging the script, putting in print_r’s of variables, echo statements etc. or using the IDE/debugger of your choice.
                    Use MODx, or the cat gets it!
                    • 12379
                    • 460 Posts
                    So I can safely assume MODx has processed the two external config files:

                    require_once ($modx->config[’base_path’] . ’assets/snippets/affiliatesforall/config.inc’);
                    require_once ($modx->config[’base_path’] . ’affiliates/lib/xmlrpc.inc’);

                    ...and that the code in the current config file either has it’s own intrinsic code faults or it’s choking on a variable being passed by one of those two config files?
                      Mostly harmless.