Oh, sorry (I thought you were using "referrer" in its technical sense...)
Well, it sounds pretty straightforward; give 'em a text field to enter another user's username (more reliable than other possibilities), check to see if that username is genuine (so that they don't say SantaClaus referred them). If it's genuine, set the cookie.
If/when they sign up, get the cookie (if it's there). Delete it (to reduce the risk of the referral being counted twice).
There's two places in the user database where it can go, depending on whether you want to know later on who referred who or not.
If you do, have a "referred_by" field in the user database that contains the (id of) the username of the user that referred them. Then you can search this for a given username to find out who that user referred.
If you don't care, then a simple numeric field "referrals" could be used instead; increment a user's "referrals" field when one of their referrals signs up. I'd prefer the first myself - it preserves more information.
Or just wait until they do sign up before finding out who referred them, and do the database thing then - skip the cookie completely. This thing about registration vs. signing up has got me a bit. What does registration do and what does signing up do? I ask because I'm left wondering why the cookie is necessary when you'd presumably have a database record to store the information in.
You certainly would be wanting to store the referral information in the database at some stage - then it's always available to you, not just when the user happens to be hitting your site - and if it's going in the database later, why not put it in sooner?