PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
fastfingertips
Forum Contributor
Posts: 242 Joined: Sun Dec 28, 2003 1:40 am
Contact:
Post
by fastfingertips » Thu Feb 05, 2004 4:43 am
I'm using CURL to get a balance history, and i'm trying to print the results. Also because is not my web server i cannot set the default page si i must avoid that "Virtual Directory message".
Unfortnatelly nothing haoppens
Code: Select all
<?php
function myHistory()
{
$link="https://www.e-gold.com/acct/historycsv.asp";
$pass="************";
$account="**********";
$batch="********* ";
$theString ="historycsv.asp?batchfilter=$batch";
$theString .="&PassPhrase=$pass";
$theString .="&AccountID=$account";
$ch = curl_init("https://www.e-gold.com/acct/");
$fp = fopen($theString, "r");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
curl_close($ch);
while ($data = fgetcsv($fp, 1000, ","))
{
$num = count($data);
echo "<p> $num fields in line $row: <br />\n";
$row++;
for ($c=0; $c < $num; $c++)
{
echo $data[$c] . "<br />\n";
}
}
fclose($fp);
}
?>
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Thu Feb 05, 2004 7:13 am
try the following:
Code: Select all
//...skipped......
//$fp = fopen($theString, "r");
$fp = fopen($theString, "w+");
//...skipped.......
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//...skipped.........
fastfingertips
Forum Contributor
Posts: 242 Joined: Sun Dec 28, 2003 1:40 am
Contact:
Post
by fastfingertips » Thu Feb 05, 2004 7:32 am
w+ means to write the file and i cannot change it
. I must take only what is inside, so how can i do that?
Anyway i have tried as you said and still not working.
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Thu Feb 05, 2004 11:06 am
1. You need to pass to curl "writable" file pointer.
2. w+ means "read and write, truncate if exists, create if not exist"
3. To read from that pointer you need to [php_man]rewind[/php_man]($fp) after the curl_exec call.
4. Don't set CURLOPT_RETURNTRANSFER unless you want to get the response into some variable . To store response in the file you don't need this option.
fastfingertips
Forum Contributor
Posts: 242 Joined: Sun Dec 28, 2003 1:40 am
Contact:
Post
by fastfingertips » Thu Feb 05, 2004 11:34 am
My code looks now:
Code: Select all
<?php
function myHistory()
{
$link="https://www.e-gold.com/acct/historycsv.asp";
$pass="***********";
$account="***********";
$batch="********";
$theString ="historycsv.asp?batchfilter=$batch";
$theString .="&PassPhrase=$pass";
$theString .="&AccountID=$account";
$ch = curl_init("https://www.e-gold.com/acct/");
$fp = fopen($theString, "r");
$fp = fopen($theString, "w+");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
rewind($fp);
curl_close($ch);
while ($data = fgetcsv($fp, 1000, ","))
{
$num = count($data);
echo "<p> $num fields in line $row: <br />\n";
$row++;
for ($c=0; $c < $num; $c++)
{
echo $data[$c] . "<br />\n";
}
}
fclose($fp);
}
?>
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Thu Feb 05, 2004 1:28 pm
Code: Select all
<?php
function myHistory()
{
$link="https://www.e-gold.com/acct/historycsv.asp";
$pass="***********";
$account="***********";
$batch="********";
$theString ="historycsv.asp?batchfilter=$batch";
$theString .="&PassPhrase=$pass";
$theString .="&AccountID=$account";
$ch = curl_init("https://www.e-gold.com/acct/");
// $fp = fopen($theString, "r");
$fp = fopen($theString, "w+");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
rewind($fp);
curl_close($ch);
while ($data = fgetcsv($fp, 1000, ","))
{
$num = count($data);
echo "<p> $num fields in line $row: <br />\n";
$row++;
for ($c=0; $c < $num; $c++)
{
echo $data[$c] . "<br />\n";
}
}
fclose($fp);
}
?>
fastfingertips
Forum Contributor
Posts: 242 Joined: Sun Dec 28, 2003 1:40 am
Contact:
Post
by fastfingertips » Thu Feb 05, 2004 1:58 pm
Yes but instead to display me the results gives me "This Virtual Directory does not allow contents to be listed. " And because is a sub-domain i caanot set the default file.
Any suggestion?
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Thu Feb 05, 2004 5:02 pm
change this:
Code: Select all
$ch = curl_init("https://www.e-gold.com/acct/");
to this:
Code: Select all
$ch = curl_init("https://www.e-gold.com/acct/".$theString);
and try.
I think it's not issue with your script, but instead is how the e-gold works (which I know nothing about
).
fastfingertips
Forum Contributor
Posts: 242 Joined: Sun Dec 28, 2003 1:40 am
Contact:
Post
by fastfingertips » Thu Feb 05, 2004 11:54 pm
The e-gold will give me a CSV file.
I was thinking to take him like a string, that using that csv function provided by PHP to format data and to display them in my page. My problem is that i cannot display the received file because it gives me that error.
I know that is a tricky problem, but i'm a curl new user
.
Any ideas?