Forum Moderators: coopster & phranque

Message Too Old, No Replies

Cookies and CGI

Using cookies to control CGI output

         

runner

5:34 pm on Nov 13, 2004 (gmt 0)

10+ Year Member



I'm working on my first web-based perl project... I need to come up with a way to print a calendar on every page of my web site. The visitor must be able to select the month of the calendar to display. Whatever month is selected must remain constant as the visitor navigates through the site. They can change months at any time but whatever it changes to must remain constant until they change it again themselves.

I think I've decided on cookies + an SSI include that execs a perl CGI script.

The CGI script will look for a cookie that contains the user's currently selected month and then spit out the appropriate calendar. If there is no existing cookie, it will default to printing the current month's calendar.

Since I've never done any web-based programming before I have some questions concerning how to approach this project.

There are two basic tasks this system will have to perform: 1) script to print out the currently selected calendar and 2) script to manage the "month" cookie. Should I have one script perform both functions or should I separate them?

Since I'm a beginner at this I am leaning towards making the perl script as simple as possible and not having it manage the cookies.

There would be a "prevous month" and "next month" link on the calendar that would call a separate script (perl CGI or embedded java) that would set or change the month listed in the cookie and then tell the page to refresh. Upon refreshing, the SSI include for the calendar would be a CGI script that will read the cookie info and provide the correct calendar.

The problem is that I don't know if this is a hokey way of doing things. Any advice would be appreciated.

Bluepixel

3:49 pm on Nov 22, 2004 (gmt 0)

10+ Year Member



I would certainly set the cookie in the calender script.

You can set it with CGI or CGI::Lite, whatever you have on your webserver. Have a look at search.cpan.org, there are a lot of Modules there so you don't have to do everything yourself.
If you search a little bit on the web, you can find some calender scripts. I simply would use them as a base and modify them for your needs since you are a beginner.
eg. [ftls.org...] but I haven't looked at it, so I can't tell if it's good or not.