#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    120
    Rep Power
    2

    Pass get variables through https url using curl


    I'm trying to pass variables through an https url using curl and the idea would be to get the xml doc and grab the attribute value from the xml doc. I have the following code but I get a few errors when trying to accomplish this with the code I have. I'd thought it would be easier to accomplish but it's not looking that way. Here is the code I have and the errors I'm getting. When sending the url through the url bar in the browser without using curl or anything, just doing it manually with some test variables, the xml doc shows up fine with value I need which is the total_charge for shipping. I need to grab that attribute value and turn it into a php variable so I can display it on my website, or pass it through to paypal as the shipping cost. Thanks in advance for your time and help.

    PHP Code:
    $xml 
                    weight_system="IMPERIAL" shipper_number="000222000" destination_postal_code="'
    .$data5['zip'].'" service_type="1" 
                '

                 
                
    $xml2 
                    total_pieces="'
    .$value.'" total_weight="'.$weight.'" 
                '
    ;          
                         
                
    $token 'A1W2EEEDDD';  
                
    $base_url 'https://www.shippingco.com/XML/RatingXML.jsp';  

                
    $request_url $base_url '?'.htmlentities('shipment=<shipment ' $xml '><total ' $xml2 '/></shipment>&token=' $token); 
                 
                
    // Get cURL resource 
                
    $curl curl_init(); 
                
    // Set some options - we are passing in a useragent too here 
                
    curl_setopt_array($curl, array( 
                    
    CURLOPT_SSL_VERIFYPEERfalse
                    
    CURLOPT_SSL_VERIFYHOSTfalse
                    
    CURLOPT_RETURNTRANSFER => 1
                    
    CURLOPT_URL => $request_url
                    
    CURLOPT_USERAGENT'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'
                    
    CURLOPT_FAILONERROR => false 
                
    )); 
                
    // Send the request & save response to $resp 
                
    $result curl_exec($curl);
                
    var_dump($result);
                
    // Close request to clear up some resources 
                
    header('Content-type: application/xml'); 
                
    curl_close($curl); 
                 
                
    $xmlGet = new DOMDocument($result); 
                
    $searchNode $xmlGet->getElementsByTagName('rate'); 
                         
                
    $attrs = array();  
                for (
    $i 0$i $searchNode->attributes->length; ++$i) {  
                      
    $node $searchNode->attributes->item($i);  
                      
    $attrs[$node->nodeName] = $node->nodeValue;  
                }  
                
    var_dump($attrs); 
    errors:

    Undefined property: DOMNodeList::$attributes in...
    Trying to get property of non-object in...

    and bool(false) when doing var_dump($result)
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7170
    and bool(false) when doing var_dump($result)
    That means the cURL request failed. echo curl_error($curl) to see why.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    120
    Rep Power
    2
    this is what was echoed,

    SSL certificate problem: self signed certificate in certificate chain

    not sure what that means
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    120
    Rep Power
    2
    Do you think I would need to purchase a CA or SSL certificate for my website or is there a way I can retrieve that xml data from the url and parse the data to echo out one of the attribute's values? I'm just not sure if the reason I can't access the data is because my website isn't secured with an SSL or CA certificate or because there is something else I have to do. I'm going to call the shipping company that I'm trying to retrieve the xml data from using cURL and see what the issue might be there and hopefully they will be able to help me out with this. I'll post back here if I get some answers from the company but if anyone here may know how to get around this SSL error I'm all ears. Thanks for your time and help!
  8. #5
  9. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7170
    Are you on a linux or windows server?
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    120
    Rep Power
    2
    Linux
  12. #7
  13. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    do you understand what SSL (or rather TLS) does and what it's for? Because your current setup makes no sense whatsoever.

    Using TLS without verifying the certificate is a joke. It's like handing secret information to somebody over a secure phone line, but you have no idea who that person is. What do you gain from all the secrecy then?

    I see two options:
    • If the data you send is not critical, forget about TLS. Turn it off and use plain HTTP.
    • If the data is critical, you need to read up on TLS first. You need to understand what a certificate is and what it's for. Then set up cURL properly. This consists of turning certificate verification on and adding the root certificate of the target website.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    120
    Rep Power
    2
    Ok so I'd have to go with your second option. I looked up the definition for TLS and what I got from it is that it carries encrypted data and hides it from a third party. I took this excerpt from http://searchsecurity.techtarget.com/definition/Transport-Layer-Security-TLS

    "The TLS Handshake Protocol allows the server and client to authenticate each other and to negotiate an encryption algorithm and cryptographic keys before data is exchanged."

    So I need to authenticate with the shipping companies server by turning certificate verification on, CURLOPT_SSL_VERIFYPEER => TRUE, however I read somewhere that this is done by default, and then I need to add the root certificate of the target website in my code? So I guess, would I get the root certificate path by clicking the https button in the url box and click show certificate? Is it under common name when showing the certificate? when I find that path do I add it like this, CURLOPT_CAINFO => 'path in here',

    also what in my setup makes no sense? If you could let me know how I'm setting it up wrong I can make the necessary changes to fix it so I can get this working.

    Thanks for all the help so far
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    120
    Rep Power
    2
    So I called the shipping company and they don't offer any other support other than giving a token and examples of what the url should look like to pass the get variables through to receive the xml data so I can retrieve it and do what I need to do with the data from there. So i'm not sure how I would get the path the ca certificate to solve the SSl error issue. How would I get the path to the CA or root certificate. Thanks for your time and help.

IMN logo majestic logo threadwatch logo seochat tools logo