Jump to content

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');

?>

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.