Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

implementing Curl in php script

Status
Not open for further replies.
I followed the sample but, I get some errors, while trying to open a page protected by .htaccess:
Warning: fopen(/scripts/passwd?password=new&domain=sanjan.mydomain.com&user=sanjans): failed to open stream: No such file or directory in /home/adv/public_html/curlex.php on line 10

Warning: curl_setopt(): supplied argument is not a valid File-Handle resource in /home/adv/public_html/curlex.php on line 12

Warning: fclose(): supplied argument is not a valid stream resource in /home/adv/public_html/curlex.php on line 17

My Code is;
<?
error_reporting(63);

$whmusername="sanjans";
$whmpassword="*******";

$ch = curl_init ("$fp = fopen ("scripts/passwd?password=$passwd&domain=$domain&user=$user", "r");

curl_setopt ($ch, CURLOPT_INFILE, $fp);
curl_setopt ($ch, CURLOPT_HEADER, 0);

curl_exec ($ch);
curl_close ($ch);
fclose ($fp);
?>

Got any tips?
 
All of your problems stem from this line:

$fp = fopen ("scripts/passwd?password=$passwd&domain=$domain&user=$user", "r");

Since it fails, a the rest of the errors cascade from it.

What, exactly, are you trying to do in this line? If you're trying to open a file on a web server somewhere, you need to specify a complete URL in the filename parameter. If you're trying to open a file on the local filesystem, you can't pass what appear to be GET-method variables.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
So you're trying to pipe the output from one web server to another.

That URL is not well-formed. There is a colon where there should be a forward slash.

Also, verify that the string you're constructing is correct. As a test, instead of creating the string and passing it to fopen, create the string and put it in a variable. Output that variable to the browser.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks, I got it to work, but when I use
print_r(curl_getinfo($c)); it gives me the page results and also this array. How do i get it not to print the array?

Also the :2086 is because I'm accessing the page on port 2086

Array ( => [URL unfurl="true"]http://sanja...d=new&domain=sanjan.mydomain.com&user=sanjans [content_type] => text/html [http_code] => 200 [header_size] => 82 [request_size] => 258 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 3.18 [namelookup_time] => 0.004 [connect_time] => 0.004 [pretransfer_time] => 0.004 [size_upload] => 0 [size_download] => 6003 [speed_download] => 1887.7358490566 [speed_upload] => 0 [download_content_length] => 0 [upload_content_length] => 0 [starttransfer_time] => 1.184 [redirect_time] => 0 )
 
According to the manual, with the way you're invoking it, that function should return an array.

However, that function is not returning the actual content of the page you're hitting via cURL. Unless you issue curl_setopt() with the CURLOPT_RETURNTRANSFER setting, curl_exec() will output the content of the foreign page.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top