0

I'm trying to send image and some more options to the server using curl, but I don't know why it doesn't work. Here is the code:

<?php

header('Location: https://www.reporo.com/analytics/inventory-advertiser-banner.php?clientid=xxxx&campaignid=xxxx&type=smrc');

$uploadUrl = "C:\wamp\www\autofill\demo_300x250.png";
$uploadUrl = "@$uploadUrl";


$post_data['description'] = 'Name';
$post_data['url'] = 'http://www.url.pl';
$post_data['campaignid'] = xxxxx;
$post_data['clientid'] = xxxxx;
$post_data['bannertext'] = 'some text';
$post_data['upload_smrc'] = $uploadUrl;

    foreach ( $post_data as $key => $value)
{
    $post_items[] = urlencode($key) . '=' . urlencode($value);
}
$post_string = implode ('&', $post_items);

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt ($ch, CURLOPT_REFERER, "https://www.reporo.com/analytics/inventory-advertiser-banner.php?clientid=xxxxx&campaignid=xxxxx&type=smrc");
curl_setopt ($ch, CURLOPT_URL, 'https://www.reporo.com/analytics/inventory-advertiser-banner-update.php');
$upload_result = curl_exec ($ch);

curl_close ($ch);

?>

Indexes in $post_data are right. The form is in the same link as CURLOPT_REFERER. Field action i form contain: inventory-advertiser-banner-update.php .

Moreover I can't login to this site using curl but when I logged before, redirect works so it should work.

Is it possible that this site site can't be used curl ? I ask because before I had problem with login which I didn't resolve and now this.

Maybe there is a way to workaround ?

Greetings.

Marek Zygmunt
  • 105
  • 2
  • 9
  • What are the curl errors you are getting. Might be due to security certificate issues. See http://stackoverflow.com/questions/521418/reading-ssl-page-with-curl-php and http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/ – web-nomad Sep 13 '12 at 12:38

3 Answers3

1

Turning SSL peer verification off is not good idea. If you want to use SSL peer verification you may use next solution on Windows globally for all applications:

  1. Download file with root certificates from here: http://curl.haxx.se/docs/caextract.html
  2. Add to php.ini:

curl.cainfo=C:/path/to/ca-bundle.crt

that's all magic, CURL can now verify certificates.

WayFarer
  • 1,040
  • 11
  • 19
0

This may not be the cause, but you need to urlencode POST keys and values if you're building the POST string manually.

foreach ($post_data as $key => $value) {
    $post_items[] = urlencode($key) . '=' . urlencode($value);
}
$post_string = implode ('&', $post_items);

Otherwise you'll get all kinds of unexpected results if any of your keys or values contains &, = etc.

That being said, you can use the array directly with CURLOPT_POSTFIELDS instead:

curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_data);

lafor
  • 12,472
  • 4
  • 32
  • 35
-1

You are likely to have problem with CURLOPT_SSL_VERIFYHOST

Try

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
Baba
  • 94,024
  • 28
  • 166
  • 217
  • Please note that [disabling VERIFYPEER or VERIFYHOST makes the connection vulnerable to MITM attacks](http://stackoverflow.com/a/13742121/372643). – Bruno Nov 21 '14 at 11:26