...

View Full Version : Importing Data From External Text File



Candrias77
11-06-2003, 11:18 PM
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?op=rates&instId=ourID

Then the following text is returned:

#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.

missing-score
11-06-2003, 11:24 PM
i dont know if this will work, i have never done anything like this before, but you could try:




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...

Candrias77
11-06-2003, 11:41 PM
No, just gives me:

Warning: Failed 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

Nightfire
11-07-2003, 01:37 AM
As far as I know, you can't include pages from a secure server

missing-score
11-07-2003, 07:10 AM
you may want to try something like:



$err = NULL;
$socket = fsockopen('www.somesite.com', 80, $err);

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


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.

bcarl314
11-07-2003, 12:27 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum