0

When I use the following code, i redirects to my own domain with https (I get 404 error because I dont use SSL on my domain)

EDIT: If my URL where the curl script is http://example.com/index.php it redirecting to https://example.com.com/index.php

It's not the same problem as other questions. I get error 404. I dont get the error with where I need to use curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$url = 'https://www.homepage.com';
$fields = array('username'=>'abc', 'password'=>'1234', 'loginbutton'=> 'Login');

$postvars='';
$sep='';
foreach($fields as $key=>$value)
{
    $postvars.= $sep.urlencode($key).'='.urlencode($value);
    $sep='&';
}

$ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

$result = curl_exec($ch);

curl_close($ch);

echo $result;
Hans
  • 1
  • 1
  • This may help [cuRL returnin 404 error](http://stackoverflow.com/questions/21001264/curl-returnin-404-error) – Amous Apr 17 '16 at 08:06
  • could somebody please help? – Hans Apr 18 '16 at 16:54
  • Hi Hans, Welcome to SO. I see you've edited your question but it's still a bit unclear what is going on. Can you include the output of `var_dump(curl_getinfo($ch)); var_dump(curl_error($ch));` after the call to `curl_exec()`? It sounds like the 404 issue may be a server configuration (.htaccess?) problem rather than a curl problem. – drew010 Apr 18 '16 at 22:06

0 Answers0