I'm a little rusty on this as I haven't used cookies for a while, but it's pretty easy. I'm going to assume you're using PHP to serve your banners. (If you're using a different language, there should be analogous functions.)
To create a cookie, do this
PHP Code:
setcookie("My Affiliate Program", "Partner Site Info", time() + 3600);
And to check if a cookie's there
PHP Code:
if (isset($_COOKIE["My Affiliate Program"]))
{
// Do something
}
And that's basically it. You presumably want persistent cookies, so you must set the expiry time (otherwise it will be lost when the browser closes). As you're inserting a banner into other people's pages, you may need to set the domain parameter too (not used above).
Here are a
couple of introductory tutorials and
more detail from php.net.
Cookies form part of the header, so you need to send them before HTML output starts. As you're inserting a banner somewhere in the middle of someone else's page, you won't be able to do that. (I think. Never tried this.)
This page runs through a few methods for getting round the problem using iframes and faux images. (It's actually about cookie stuffing, or stealing someone else's commissions. This is of course a
bad thing, but it looks like the same methods can be used - more legitimately - to insert your own cookies. If anyone knows other ways of adding tracking cookies via a banner then I'd be interested to hear.)
Cookie spec, which you should probably check out.
And
JavaScript cookie control, just FYI.