I am trying to send POSTDATA via cURL with PHP, and I think the message is not sending
$ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLINFO_HEADER_OUT, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_URL, $url); $t = curl_exec($ch);
I donβt know why, but I try to enter the page and when I dump $ t, I always see the form, curl_error is empty, what can I do to debug this? The page trying to log in is not mine!
I have a local form emulating cURL and its OK:
<form action="$url" method="POST"> <input type="hidden" name="username" value="$uspw" /> <input type="hidden" name="password" value="$uspw" /> <input type="submit" value="Send" /> </form>
It will start in $ url! Here is the $ data that I send POSTFIELDS to cURL
$data = array('username' => $uspw, 'password' => $uspw);
Yes .. user and password are the same
Headers Received:
HTTP/1.1 100 Continue HTTP/1.1 200 OK Date: Sun, 25 Nov 2012 05:23:19 GMT Server: Apache Cache-Control: no-cache="set-cookie" Content-Length: 4822 Set-Cookie: SESSIONID_portalApp=xxxxxx!-xxx!xxx; path=/ Content-Language: en X-Powered-By: Servlet/2.4 JSP/2.0 Content-Type: text/html; charset=ISO-8859-1
and after that I get the whole form, again ...
$data = array('username' => $uspw, 'password' => $uspw); $header = array('Origin: xxx', 'Content-Type: application/x-www-form-urlencoded', 'Connection: keep-alive', 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3', 'Cache-Control: max-age=0', 'Except:', 'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3', 'Accept-Encoding:gzip,deflate,sdch', 'Accept-Language:es-ES,es;q=0.8', ); $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLINFO_HEADER_OUT, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FORBID_REUSE, 0); curl_setopt($ch, CURLOPT_FRESH_CONNECT, 0); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11"); curl_setopt($ch, CURLOPT_COOKIEJAR, 'xxx.txt'); curl_setopt($ch, CURLOPT_REFERER, 'xxxx'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_URL, $url); $t = curl_exec($ch);
Thanks!