Forum Moderators: coopster

Message Too Old, No Replies

Trying to set up a basic cookie cart

for passing info to different payment processors

         

j4mes

11:09 am on Jul 6, 2004 (gmt 0)

10+ Year Member



Hi,

I want to put together a simple "cart" that will store what the user clicks to buy (and quantity), and a few other bits into a cookie, which can all be accessed in a new window, modified, what have you, and the user then select the payment method (PayPal/NoChex/etc.) and the information be passed to whichever.

Since this is a little long winded for something that needs to be simple, here's a nice diagram :)

User clicks item to buy
¦
¦
Information passed to cookie
¦
¦
User looks in "cart"
¦
¦
Cart reads cookie and displays info.
¦
¦
User selects payment method
¦
¦
Info transfered to payment processor (PayPal et al)

I posted here in PHP because it looks like the most appropriate language (Javascript is often disabled, especially of late), though if there is something more appropriate please say.

I *think* this should be fairly simple(?). I'm not after a complete solution (I've poked round Mals-e etc.) I just want the basics of setting cookies, passing the info to different processors, etc.

Huge TIA :)

James.

StupidScript

8:46 pm on Jul 6, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Note that cookies can ONLY be read from within the accepted path of the server that wrote them. If you want to send cookie data written by your server to another server, you will need to parse out the data and get it over to them after you have done so.

Basic cookie syntax from [php.net:...]

bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, int secure]]]]])

i.e.
setcookie("testcookie",$somevalue);

Once the cookie has been set, you can access it using the $_COOKIE environment variable.

i.e.
$thisvalue=$_COOKIE['testcookie'];

results in:
$thisvalue=$somevalue;

which can then be passed via CGI/email/FTP, etc. to another server.

httpwebwitch

4:47 pm on Jul 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



May I suggest you do the same thing, but use Sessions instead of cookies? PHP has redundant processes that continue to work when cookies/javascript are disabled. They're also easier to use (IMHO). There is no ironclad foolproof way to overcome stateless page requests, but Sessions are quite good, and they're the closest and most reliable thing we've got.

On the "order" page:
<?php
session_start();
$_SESSION['itemID']=$quantity;
?>

In the cart summary:
<?php
session_start();
echo $_SESSION['itemID'];
?>

When you're debugging, you can look at the contents of the session with this:

print_r($_SESSION);

It's also easy to populate a "checkout" form with all the session items, with a submit button that passes your cart into PayPal/NoChex/etc.

good luck!

j4mes

1:34 pm on Jul 8, 2004 (gmt 0)

10+ Year Member



Brilliant, thanks StupidScript and httpwebwitch for your help :)

J.