enviar formulario de una web ajena desde mi formulario de mi proyecto
no se como enviar datos desde mi propio formulario a la pagina ajena y una vez hacer el envio de datos en la pagina ajena, obtener el resultado de la consulta. es posible hacerlo?
creo que esto puede servir http://www.anerbarrena.com/jquery-post-5064/
hice la prueba sobre este codigo:
> > function curlPost($postUrl, $postFields) {
>
> $cookie = 'cookie.txt'; // Setting a cookie file to store cookie
>
> $ch = curl_init(); // Initialising cURL session
>
> // Setting cURL options
> curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // Prevent cURL from verifying SSL certificate
> curl_setopt($ch, CURLOPT_FAILONERROR, TRUE); // Script should fail silently on error
> curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE); // Use cookies
> curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); // Follow Location: headers
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Returning transfer as a string
> curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); // Setting cookiefile
> curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); // Setting cookiejar
> curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1a2pre) Gecko/2008073000 Shredder/3.0a2pre
> ThunderBrowse/3.2.1.8"); // Setting useragent
>
> curl_setopt($ch, CURLOPT_URL, $postUrl); // Setting URL to POST to
> curl_setopt($ch, CURLOPT_POST, TRUE); // Setting method as POST
>
> curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postFields)); // Setting POST fields as array
>
> $results = curl_exec($ch); // Executing cURL session
> curl_close($ch); // Closing cURL session
>
> return $results;
> }
y lo uso asi
> > $user ="userxxx";
> $pass = "passxxxxxxx";
>
>
> $login_url = "http://www.xxxxx.com/repositorio/consultas_web/";
> $post_array = array ('login' => $user,
> 'password' => $pass); // Building post array.
>
>
> $results = curlPost($login_url, $post_array);
no envia solo me muestra la pagina y no hace el envio post
Tenes habilitado curl? Podes ver el archivo access.log de tu servidor para ver si hizo la peticion.
en el file access.log en las ultimas lineas aparece esto, efectivamente muestra la fecha 12/Oct/2016:13:43:06 use chrome
::1 - - [12/Oct/2016:13:43:06 -0400] "GET /xampp/img/head-windows.gif HTTP/1.1" 200 1362 "http://localhost/xampp/head.php" "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"
::1 - - [12/Oct/2016:13:43:06 -0400] "GET /xampp/img/head-for.gif HTTP/1.1" 200 791 "http://localhost/xampp/head.php" "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"
::1 - - [12/Oct/2016:13:43:05 -0400] "GET /xampp/img/xampp-logo-new.gif HTTP/1.1" 200 4878 "http://localhost/xampp/head.php" "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"
::1 - - [12/Oct/2016:13:43:05 -0400] "GET /xampp/start.php HTTP/1.1" 200 3801 "http://localhost/xampp/" "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"
::1 - - [12/Oct/2016:13:43:05 -0400] "GET /xampp/navi.php HTTP/1.1" 200 4060 "http://localhost/xampp/" "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"
::1 - - [12/Oct/2016:13:43:07 -0400] "GET /xampp/img/apachefriends.gif HTTP/1.1" 200 979 "http://localhost/xampp/navi.php" "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"
::1 - - [12/Oct/2016:13:43:07 -0400] "GET /xampp/xampp.js HTTP/1.1" 200 573 "http://localhost/xampp/navi.php" "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"
::1 - - [12/Oct/2016:13:43:07 -0400] "GET /xampp/img/bitnami-xampp.png HTTP/1.1" 200 22133 "http://localhost/xampp/start.php" "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"
::1 - - [12/Oct/2016:13:43:08 -0400] "GET /xampp/img/strichel.gif HTTP/1.1" 200 61 "http://localhost/xampp/navi.php" "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"
::1 - - [12/Oct/2016:13:46:36 -0400] "GET /applications.html HTTP/1.1" 200 1441 "http://localhost/xampp/navi.php" "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"
::1 - - [12/Oct/2016:13:46:36 -0400] "GET /bitnami.css HTTP/1.1" 200 2142 "http://localhost/applications.html" "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"
no hace login, alguien ve algun error?
MOD: No hacer doble post!
Has un phpinfo(), para ver si esta habilitado curl o
function _isCurl(){
return function_exists('curl_version');
}
Tambien podes checkear error.log para ver el error de php.
$login_url = "http://www.xxxxx.com/repositorio/consultas_web/";
Estas seguro tambien de que la url es la correcta? digo estas tratando de hacer un login, usa la url que te redireccionara el formulario del login.