0

I have this script:

$ch = curl_init($url_path.'admin/');
$cookiefile = $srv_path."admin/cookie.txt" ;
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec ($ch);

//
curl_setopt($ch, CURLOPT_PROXY, "http://127.0.0.1.:8888");
curl_setopt($ch, CURLOPT_PROXYPORT, 8888);
curl_setopt($ch, CURLOPT_HEADER, 1);
preg_match('/^Set-Cookie: (.*?);/m', curl_exec($ch), $m);

$xid = substr($m[1], 10);    


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url_path.'admin/login.php');

// ENABLE HTTP POST
curl_setopt($ch, CURLOPT_POST, 1);
//SET POST PARAMETERS : FORM VALUES FOR EACH FIELD 
curl_setopt($ch, CURLOPT_POSTFIELDS, 'xid_7d781='.$xid.'$username=*****&password=******&mode=login&usertype=P&redirect=admin');

# Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL # not to print out the results of its query.
# Instead, it will return the results as a string return value # from curl_exec() instead of the usual true/false.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Allow redirection     
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile); 
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);

// 
//echo('EXECUTE 1st REQUEST (FORM LOGIN)');
$page = curl_exec ($ch);
curl_close ($ch);
echo $page;

but when i call it, the form fields are blank. Furthermore the method that returns is GET and not POST. Why returns GET?

The same code if i try it for another domain run correctly and that is also very strange. Is it possible the post method blocked by something?

I tried to echo any possible errors with var_dump(curl_error($ch)); but the string is empty.

Gio7
  • 33
  • 7
  • "method that returns is GET and not POST". This makes no sense. You can only use one method per HTTP request. the method and the type of data returned are not connected. – ADyson Jul 04 '16 at 10:46
  • Were you able to produce the correct output with command line curl? What was the correct command line command and what was its output? – scones Jul 04 '16 at 11:14
  • Just try to check curl is enabled or not on your current server.You can check through `phpinfo()` or you can see this link http://stackoverflow.com/questions/13433946/how-to-check-if-curl-is-enabled-or-disabled – Mohammad Sayeed Jul 04 '16 at 11:25
  • Ι am trying to produce the results in browser. The output is to return me the form fields empty. I use HttpFox (firefox adds-on) to check the returned method and is GET. I have already check if is enabled. The result is true. – Gio7 Jul 04 '16 at 11:59
  • Just noticed an error, dont know if it helps. `curl_setopt($ch, CURLOPT_PROXY, "http://127.0.0.1.:8888");` The IP adress has a trailing dot, before the semicolon. Also you dont need the port number, just the IP address as you set the port in the option below. – Fjarlaegur Jul 04 '16 at 12:59
  • Thank you for the notice Clemenz but i have the same results again. – Gio7 Jul 04 '16 at 13:33
  • @user3616435 You said " I use HttpFox (firefox adds-on) to check the returned method and is GET." If understand you correctly, you are trying to send a POST request to a server that only supports GET for that method? Either you need to reconfigure the server to support POST for that method, or change your request to GET. – ADyson Jul 04 '16 at 14:18

0 Answers0