×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

CGI vs. CGI::Cookies

CGI vs. CGI::Cookies

CGI vs. CGI::Cookies

(OP)
I've looked at the docs for CGI and CGI::Cookie but I'm confused about which one to use. Well, here's what I'm trying to do. I have a script that will force a login if a cookie does not exist or the expiration date is invalid. I want to reset the expiration date to an invalid date to force a login. Should I use CGI or CGI::Cookie. I know with CGI you can create cookies but I've seen no examples about deleting a cookie or modifying one. Thanks for any help in advance. A small example would help also.

RE: CGI vs. CGI::Cookies

The following does not delete the cookie, but it sets the value to null and 'Some Cookie value here' alternately.  Maybe, it can be modified to do what you want.  Feel free to ask if you need clarification.  You can copy/paste this into a file in your cgi-bin and it will produce a page with a button that switches the value of the the cookie between null and 'Some Cookie value here'.



#!/usr/local/bin/perl
use CGI;
$query = new CGI;
$thisCGI = $query->url();

$cookThis = $query->cookie(-name=>'cookThis');
if ($cookThis)
    {
    $cookie = $query->cookie(-name=>"cookThis",
        -value=>'',
        -expires=>"+1h");
    }
else
    {
    $cookie = $query->cookie(-name=>"cookThis",
        -value=>"Some Cookie value here",
        -expires=>"+1h");
    }

print $query->header(-cookie=>$cookie);
print "<BR>CookThis is $cookThis<BR>";
print $query->start_html(-title=>"cook this");
print $query ->start_multipart_form('POST',"$thisCGI");
print '<BR>',$query->submit('doWhat','cook');
print $query->end_form;
print $query->end_html;


'hope this helps...

 
 
 
 keep the rudder amid ship and beware the odd typo

RE: CGI vs. CGI::Cookies

(OP)
Thanks goBoating! That helps a lot. I also saw a module called HTTP::Cookies. Any comment on using that one?

RE: CGI vs. CGI::Cookies

I don't personally know that much about cookies, but it seems to me that if you want to cut through the confusion of these multiple modules, just find the cookie specification docs at w3.org and learn to do it manually.  I do all of my CGI and HTML manually and it is much easier than using any of the modules and learning all of their object-oriented functions.  Much more powerful this way too because you're not limited by what someone else decided to implement or not.


Sincerely,
 
Tom Anderson
CEO, Order amid Chaos, Inc.
http://www.oac-design.com

RE: CGI vs. CGI::Cookies

Haazi2,
' Never messed with HTTP::Cookies so I can't comment on it.  I do know that CGI.pm will do the job as shown above.

Tom,
I agree with you to a point about manually generating the code.  However, I have found that there are quite a few things that I do repeatedly-repeatedly that CGI.pm helps with.  I use the module to build the frequently used parts of pages and then mix in manually generated stuff as needed.  It cuts down on the amount of code I have to write.   Basically, I use the module for what its good for.  There is some significant economy of effort gained.  Additionally, CGI.pm provides a function based interface that is not object oriented.  If you don't like the object syntax, many of the methods can be called just like functions.

Good Luck haazi2,  let us know if you need more......

 
 
 
 keep the rudder amid ship and beware the odd typo

RE: CGI vs. CGI::Cookies

(OP)
Thanks goBoating and tanderso!

I'll use the CGI.pm module but will aslo look at doing things by hand also. Doing it by hand can help me further increase my perl knowledge. Again, Thanks guys!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close