Jump to content

Curl


johnsmith153

Recommended Posts

If I type in https://www.site.com/page.php?var1=1&var2=5&var3= in my browser, I get exactly what I want.

 

If I use below, it doesn't work.

 

Surely both these are the same.

 

$post_fields="var1=1&var2=5&var3=";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.site.com/page.php');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response_string = curl_exec($ch);
curl_close($ch);

 

There are no $_GET requests on the target page - I have used $_REQUEST for all.

Link to comment
https://forums.phpfreaks.com/topic/130019-curl/
Share on other sites

It works for me...

test.php

<?php
$post_fields="var1=1&var2=5&var3=";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.mysite/test2.php');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response_string = curl_exec($ch);
curl_close($ch);

echo '<textarea rows="50" cols="100">'.$response_string.'</textarea>';
?>

 

test2.php

<?php
    print_r($_REQUEST);
?>

 

Outputs:

Array ( [var1] => 1 [var2] => 5 [var3] => )

 

----

If you are returning HTML, are you sure it's just not visible?

Link to comment
https://forums.phpfreaks.com/topic/130019-curl/#findComment-674149
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.