cURL代码注册表单的web应用程序不工作显示页面的顶部


cURL code for registration form to web app not working showing top of page

我已经创建了一个cURL php文件&将其包含到index.php文件中。部分代码显示在页面的顶部。我不是最好的PHP程序员,但我相信它是正确的编码。下面是PHP文件的代码:

<?php
//array of data to be posted
$post_data = array(
   'FirstName' => urlencode($firstname),
   'LastName' => urlencode($lastname),
   'UserIdentifier' => urlencode($regemail),
   'Password' => urlencode($regpass),
   'ReferrerAttribution' => '[referrer here]'
);
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
    $post_items[] = $key . '=' . $value;
}
//final string using implode()
$post_string = implode ('&', $post_items);
//create cURL connect
$curl_connection =
  curl_init('https://integration.[domain here].com/v1/[folder here]');
//set options
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,
  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_connection, CURLOPT_HEADER, true);
//set header
$header = array (
        'POST https://integration.[domain here].com/v1/[folder here] HTTP/1.1'r'n',
        'Content-Type: application/x-www-form-urlencoded'r'n',
        'Authorization: Basic "[auth key here]"'r'n'
 );
//set post data
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform request
$result = curl_exec($curl_connection);
//show request info
print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' .
                curl_error($curl_connection);
//close
curl_close($curl_connection);
?>

这是页面顶部的错误:

Warning: curl_setopt(): supplied argument is not a valid cURL handle resource in /home/[main]/public_html/[folder]/signup.php on line 24
    Array ( [url] => https://integration.[domain].com/v1/[folder] [content_type] => text/html [http_code] => 401 [header_size] => 381 [request_size] => 285 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 2.294219 [namelookup_time] => 0.002752 [connect_time] => 0.081426 [pretransfer_time] => 0.26445 [size_upload] => 74 [size_download] => 58 [speed_download] => 25 [speed_upload] => 32 [download_content_length] => -1 [upload_content_length] => 74 [starttransfer_time] => 0.345831 [redirect_time] => 0 ) 0-

[]括号用来显示我不能公开的信息。提前感谢您的帮助。哦,这是我的第一篇文章。

欢迎来到StackOverflow!在下面的代码行中,您传递了一个没有定义的无效参数$ch。修改为$curl_connection

:

curl_setopt($ch, CURLOPT_POST, 1);
应:

curl_setopt($curl_connection, CURLOPT_POST, 1);
编辑:

您也没有将您定义的标头应用到您的请求。你应该这样做:

curl_setopt($curl_connection, CURLOPT_HTTPHEADER, $header);