Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Cookie Maker

by isotope (Chaplain)
on Sep 09, 2000 at 01:51 UTC ( #31692=sourcecode: print w/ replies, xml ) Need Help??

Category: CGI Programming
Author/Contact Info
Description: I use this CGI script every time I have to do some work with cookies. It can be used to set completely arbitrary cookies, and to renew, edit, or delete existing cookies. I wrote it a long time ago, so please excuse the newbie flavor to it. Maybe I'll work on an update soon. Consider it covered by the GPL.
$| = 1;
use CGI qw(:form);
use URI::Escape;
my $query = new CGI;

my $name = $query->param('name');
if ($name eq "") {
else {
    my $value = $query->param('value');
    my $exp = $query->param('exp');
    if ($query->param('cookie_action') eq "Delete") {
        $exp = "-1d";
    my $path = $query->param('path');
    my $cookie = $query->cookie(-name=>$name,
    print $query->header(-cookie=>$cookie,
    print <<"End";
    <TITLE>Cookie maker</TITLE>
    <FONT SIZE="+2"><A HREF="cookie.cgi">Refresh</A></FONT><BR>

sub form {
    print $query->header(-expires=>'-1d');
    print <<"End";
    <TITLE>Cookie Maker</TITLE>
    <H1>Please enter your cookie parameters</H1>
    <FORM ACTION="cookie.cgi" METHOD="GET">
    <INPUT TYPE="text" NAME="path" VALUE="/cgi-bin/"> Path<BR>
    <INPUT TYPE="text" NAME="name" VALUE=""> Cookie Name<BR>
    <INPUT TYPE="text" NAME="value" VALUE=""> Cookie Value<BR>
    <INPUT TYPE="text" NAME="exp" VALUE="+3M"> Expiration date<BR>
    <INPUT TYPE="submit" NAME="cookie_action" VALUE="Make cookie">
    print <<"End";

sub mycookies {
    print "Your cookies:\n";
    print "<TABLE BGCOLOR=\"#FFFF00\" BORDER=\"1\">\n";
    print "<TR><TH>Name</TH><TH>Value</TH><TH>Cookie Path</TH><TH>Rene
+wal Date</TH><TH>Action</TH></TR>\n";
    my @cookies = split(/\; /, $ENV{'HTTP_COOKIE'});
    foreach my $cookie (@cookies) {
        $cookie = uri_unescape($cookie);
        my ($name, $value) = split(/=/,$cookie);
        print "<TR>\n";
        print "<FORM ACTION=\"cookie.cgi\" METHOD=\"GET\">\n";
        print "<INPUT TYPE=\"hidden\" NAME=\"name\" VALUE=\"$name\">\n
        print "<INPUT TYPE=\"hidden\" NAME=\"value\" VALUE=\"$value\">
        print "<TD>$name</TD>\n";
        print "<TD>$value</TD>\n";
        print "<TD><INPUT TYPE=\"text\" NAME=\"path\" VALUE=\"/cgi-bin
        print "<TD><INPUT TYPE=\"text\" NAME=\"exp\" VALUE=\"+3M\"></T
        print "<TD><INPUT TYPE=\"submit\" NAME=\"cookie_action\" VALUE
+=\"Renew\"><INPUT TYPE=\"submit\" NAME=\"cookie_action\" VALUE=\"Dele
        print "</FORM>\n";
        print "</TR>\n";
    print "</TABLE>\n";

Comment on Cookie Maker
Download Code
Replies are listed 'Best First'.
RE: Cookie Maker
by joe (Acolyte) on Oct 17, 2000 at 04:59 UTC
    Thanks isotope. very handy. One question though... How can you get the "path" and "expiration" from a cookie? Are they even sent down with a request? They don't show up even with CGI::raw_cookie.
      path and expiration are used internally by the browser. They are not transmitted to the server. Only the name/value pair for each cookie is actually sent to the server.


Back to Code Catacombs

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://31692]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2015-11-25 11:50 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (674 votes), past polls