Trying some simple code to work with cURL but no lucky.. I tried to POST a form but nothing happens and no error occurs.
Here is my code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost:8888/curl/home2.php');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'usuario=teste&senha=12345');
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec ($ch);
print_r(curl_getinfo($ch));
echo curl_errno($ch) . '-' .
curl_error($ch);
echo $store;
When submit happens on the form home2.php it should go to another page and return some data. Am i doing something wrong?
--- UPDATE
Here is my simple home2.php code:
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<form method="POST" action="login.php" id="formLogin" name="formLogin">
Usuario <input name="login" type="text">
Senha <input name="senha" type="text">
<input type="submit">
</form>
</body>
</html>
login.php :
<?php
$login = $_POST['login'];
$senha = $_POST['senha'];
if($login == "teste"){
echo "OK";
}
?>
It should be "OK" as my result, right?
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);usuario, but your form is expectinglogin. You also need to submit towardslogin.phpand nothome2.php. What actually happens when you submit the form onhome2.phpthrough a browser is that the browser sends the form input tologin.php- it never gets sent tohome2.php.