Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Calling external script to get log entry and cookie info

Trying to track users through offsite shopping cart processor

11:52 pm on Dec 5, 2003 (gmt 0)

Preferred Member

10+ Year Member

joined:Sept 16, 2003
votes: 0

I'm using PHP to define a cookie uniquely identifying users who visit my site.

Unfortunately, I use an offsite shopping cart for the actual order entry, so I lose track of them as they leave my site, making it challenging and time-consuming to track orders back to the unique cookie identifiers.

I have a small amount of room in the header and footer of the shopping cart that I can use to call external javascript.

A couple of different thoughts I had:

1) Is it possible to call something (like an image) which cannot be be cached by proxy servers, so I would be guaranteed to get its access logged everytime a user hit a page?

2) If my site is Site Foo and the external shopping cart site is Site Bar, will an external javascript hosted on my site be able to read cookies from Site Foo? If so, I suppose I can create a script which reads the cookie, but how do I then get that cookie entry into my server logs (or even better, some other file or MySQL DB) so that I can quickly tie my unique userid information back to purchases?



7:42 pm on Dec 10, 2003 (gmt 0)

Senior Member from CA 

WebmasterWorld Senior Member httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 29, 2003
votes: 0


Javascript can only read cookies from within the same realm/domain. You can not access cookies on another server, even if it is *your* shopping cart. Doesn't seem fair, does it?

When you're using someone else's shopping cart system, your ability to access it from within your own page is limited. Javascript is not going to help you.

So... This becomes a PHP question.

Don't keep track of people with a cookie. They may have cookies turned off. The best way to track users is using SESSION variables. In PHP, sessions use cookies if they're available, or a querystring appended to the URL if they're not.

I'd like to assume you're using a good shopping gateway with all the usual bells and whistles. A lot of shopping gateways have a way to configure a "thank you" page to which it sends the user to after their purchase is confirmed. Sometimes this is done with hidden <input> tags, and sometimes it's configured along with an account. This thankyou page can either be an HTML page that says "thanks!", or you can set it to be a custom PHP script. Do that.

Direct your confirmed payments to a PHP script, then in that script, display all the collections that were sent along with it. Use the code below to see them:


If your gateway is any good, it will be sending some good data along with the request for the "thank you" page. You might see unique order numbers, subtotals, product SKUs, etc. If they do, you can store those in your db.

Some gateway systems also let you SEND some variables through the payment process, and they are returned out the other end. That sounds like what you want - see if they'll do it.

You might do this:

<a href="ht*p://cartdomain.com/checkout.htm?fuzzy=wuzzy"> check out now <a>

or this:

<form action="ht*p://cartdomain.com/checkout.htm">
<input type="hidden" name="fuzzy" value="wuzzy">

Then see if fuzzy still equals wuzzy when you are returned to your site.

good luck!