Gossamer Forum
Home : General : Perl Programming :

Cookies and processes

Quote Reply
Cookies and processes
Hi folks,

Is is possible to set and test a cookie in the same perl process?

It's for a shopping cart (my first *real* script! Smile). The process would run along the lines of - if the user doesn't have a cookie, set a cookie, test to see if it's been set and if it hasn't get the IP address as the (almost) unique identifier. And if you can't get an IP for some ungodly reason, add a random number to the URL to track the user. Like this:

Code:
if ($user_has_a_cookie = 1) {
&bugger_off_to_the_next_part;
}
else {
&set_a_cookie;
&get_the_cookie; #Test to see if it was set
if ($user_has_a_cookie = 1) {
&bugger_off_to_the_next_part;
}
else {
&get_the_IP;
if ($did_I_get_an_IP = 0) {
&add_random_to_URL;
}
}
}

Or something like that! So is this possible, or will I have to do something else, and if so, any suggestions? Avoiding JavaScript is possible, I'm aware of "if document.cookies" but I want to avoid JavaScript and particularly JS cookies where possible.

Thanks,
adam

Ps. Forgot to mention - Alex, for some reason the post page goes grey when I hit submit in Communicator 4.5. I guess if you're doing a new board it doesn't really matter anyway. And my suggestion for the board would be to have something pretty much the same as the UBB, as it's quite definetly one of the best around.

Cheers!

[This message has been edited by dahamsta (edited March 27, 1999).]
Quote Reply
Re: Cookies and processes In reply to
 
I don't know how you feel about lib files but Matt Right < Matt's Script Archive > has a pretty handy Cookie-lib.pl that may help with your cookie routines. It helps set, get and manipulate coookies. You can get it at http://www.worldwidemart.com/scripts/ Maybe it will give you the insight you need to do what your wanting.

On the subject of Netscape 4.5 and the grey screen, I get it too. Wink



------------------
The Crowe crowe@darkspiral.com
www.darkspiral.com
www.lit.org
Quote Reply
Re: Cookies and processes In reply to
Crowe,

Thanks for that, I have it already. And it's Matt Wright Smile. Good old Worldwidemart is where I started learning Perl and I'm continuing my education playing around with dbMan and browsing in here when I have the time.

I suppose that rather than asking the question here, I should've just tried it out, but sometimes it's easier to ask before you code, if anything it might save a little time . Plus cookies are one of my blind spots, I can't seem to get my head around them. mod_rewrite yes, but cookies no. Weird huh? Smile

Thanks anyway!

adam
Quote Reply
Re: Cookies and processes In reply to
 
Heh. I with ya man Wink I'm still learning perl myself. Mainly modding stuff I find. This forum has been the most help, even if just to point me to other great web resoureses.

And Alex Seems to know EVERYTHING about perl so you can't go wrong with his answers Smile

I garantee I'll buy his book if he ever writes one Smile

As it stands, I spend alot of time at webereview.com on the perl section, and I'm reading Programming Perl and the Perl Cookbook, both O'Reilly books. They are excellent. I saw another book at Barnes & Noble that is All code with commentary ( 49$ ) but I still want to get it. I learn best by reading well documented code, but its nice to have the books for reference.

By all means, if anyone wants my 2 cents, don't buy perl for dummies. It wasn't worth the cash. If you have a programming background, skip right to Programming Perl ( O'Reilly ) or if you new, Start with Learning Perl ( O'Reilly ).

Maybe in the next few weeks I'll be more helpful with code rather than just URL's Smile



------------------
The Crowe crowe@darkspiral.com
www.darkspiral.com
www.lit.org
Quote Reply
Re: Cookies and processes In reply to
Just clawin' me way back up to the top in the hope I'll get noticed...