Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    New Zealand
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Importing Data From External Text File

    Hi there, I am using World Pay to do the final Credit Card processing for a client. I would like to change all the prices on the site to match the currency that is selected by the user. This is simple enough if I have the conversion rates... that's where it get's interesting.

    If I type this into my browser:
    https://select.worldpay.com/wcc/info...s&instId=ourID

    Then the following text is returned:
    Code:
    #Exchange rates
    #Thu Nov 06 23:06:19 GMT+00:00 2003
    NZD_NZD=1.0
    NZD_EUR=0.5436378022267444
    NZD_USD=0.6265429874209774
    etc.
    etc.
    etc.
    Now I figure if I could set this returned data as a string then I can explode() it and find the variables I need.

    I have never worked with opening external files before, when I try to read this file with fopen() I get a 'no such file or directory' error. Is there a speical way of calling in a text file?

    Thanks for your help, any recomendations are appreciated.
    eTheory - the theory of revolution

  • #2
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i dont know if this will work, i have never done anything like this before, but you could try:

    PHP Code:

    ob_start
    ();

    include(
    'https://select.worldpay.com/wcc/info?op=rates&instId=ourID');

    $data ob_get_contents();

    ob_end_clean();

    // use $data to explode and get info... 

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    New Zealand
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No, just gives me:
    PHP Code:
    WarningFailed opening 'https://select.worldpay.com/wcc/info?op=rates&instId=ourID' for inclusion (include_path=':./include:include/:../include:./:rightnav/:/usr/local/apache/smarty'in currency.php on line 6 
    eTheory - the theory of revolution

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    As far as I know, you can't include pages from a secure server

  • #5
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you may want to try something like:

    PHP Code:
    $err NULL;
    $socket fsockopen('www.somesite.com'80$err);

    if(
    $err != NULL){
           echo 
    $err;
    } else {
           
    fputs ($socket"GET / HTTP/1.0\r\nHost: [url]www.somesite.com\r\n\r\n[/url]");
           while(!
    feof($socket)){
                  echo 
    fread($socket4096);
           }

    im not entirely sure about ssl, (https://), i dont know if there is a port or something, i seem to remember ssl:// and tls:// when i loooked on www.php.net/fsockopen

    maybe someone else could provide some more info.

  • #6
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    im not entirely sure about ssl, (https://), i dont know if there is a port or something, i seem to remember ssl:// and tls:// when i loooked on www.php.net/fsockopen

    maybe someone else could provide some more info.
    SSL usually runs on port 443

    I think what missing's got is your best bet. One thing you may want to try is to run the script from a secured area in your site.

    Non-secure -> Secure usually causes problems. If you try to connect to a secure server from a secure server, you may have better luck.

    Anyway, if you can connect, the next thing you'll prolly want to do is instead of echoing out the content, save it to a string. Then parse the string using a regex for the variable information you want.

    Hope this helps.


  •  

    Posting Permissions

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