Jump to content

POSTing to a shopping cart with cURL


ad_shipping

Recommended Posts

I have to write a PHP script that recieves POST information when a customer clicks an "Add To Cart" button, alters some of the data, then forwards it to the shopping cart.

 

I have it working, but when I add a product to the cart the normal way (straight from the product page to the shopping cart), it creates a different instance of a shopping cart.  I think it has something to do with cookies, but I've tried everything I can think of, and I can't get it to work.

 

I have been using cURL but I would try something different if it might work.

 

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/171835-posting-to-a-shopping-cart-with-curl/
Share on other sites

this code adds the product to shopping cart #1 but then displays shopping cart #2 (the one I want the product to go into):

 

<?php

$cookieDataString = '';
foreach( $_COOKIE as $key=>$value ) {
$cookieDataString .= $key.'='.$value.' ;';
}
$cookieDataString = rtrim($cookieDataString, ' ;');
//echo $cookieDataString;

$postDataString = '';
foreach( $_POST as $key=>$value )
$postDataString .= $key.'='.$value.'&';
$postDataString = rtrim($postDataString, '&');

$username = '**********';
$password = '**********';

$ch = curl_init('http://www.activedogs.com/cgi-activedogs/sb/order.cgi');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:application/x-www-form-urlencoded"));
//If the target server returns a redirect request using the "Location:" header directive, then follow it.
//To prevent recursive redirects, only do a max of 5 follows
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
//curl_setopt($ch, CURLOPT_MAXREDIRS, 5);

curl_setopt($ch, CURLOPT_POSTFIELDS, $postDataString);
curl_setopt($ch, CURLOPT_COOKIE, $cookieDataString);
$output = curl_exec($ch);
//$info = curl_getinfo($ch);
curl_close($ch);

header('Location: http://www.activedogs.com/cgi-activedogs/sb/order.cgi?storeid=*1459bf16ea1d408711b4452c&function=show');

?>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.