通过CURL动态地将产品添加到ZenCart

时间:2011-09-12 00:17:19

标签: php authentication dynamic curl zen-cart

我已经完成了一个创建高分辨率图像的Flash应用程序。我试图通过php脚本将这个图像作为产品添加到ZenCart。我想通过curl访问管理员,添加新产品,如果成功,则返回新创建的产品ID。

这将是脚本的登录部分:

$curl = curl_init(); 
$fields = array('admin_name'=>'user', 'admin_pass'=>'pass');
$url = 'http://www.mystore.com/login.php';

curl_setopt($curl, CURLOPT_POST,        1); 
curl_setopt($curl, CURLOPT_URL,         $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,  1);                         
curl_setopt($curl, CURLOPT_POSTFIELDS,  $fields);

$result = curl_exec($curl);

if(curl_errno($curl)){ 
    echo 'error'; 
} else {
    echo $result;
}

但遗憾的是我只收到以下错误消息:

Authorization Required

This server could not verify that you are authorized to access the document requested.     Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't     understand how to supply the credentials required.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

我尝试过使用

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

没有成功。有什么想法吗?

提前致谢

1 个答案:

答案 0 :(得分:1)

尝试使用不同类型的身份验证。 manual提及:

  

CURLAUTH_ANY是CURLAUTH_BASIC |的别名CURLAUTH_DIGEST |   CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM。

所以我会选择curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

或者如果不起作用或不支持,请尝试:

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM);