SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: cgi and cookies

  1. #1
    Destiny Manager Plebius's Avatar
    Join Date
    Nov 1999
    Posts
    682
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here are a getcookie and setcookie routine.
    You can set a cookie like this:
    print &setcookie('referer',$ENV{'HTTP_REFERER'},time,'.yourdomain.com','/');

    and get them like this:
    %cookies = &getcookies();
    $cookies{'referer'}; # this is the referer

    sub setcookie
    {
    my ($name, $value, $expiration, $domain, $path) = @_;
    $path | |= "/";
    if(not defined $value) { return; }
    return "Set-Cookie: $name=$value; expires=$expiration; path=$path; \n";
    }

    sub getcookies
    {
    my (@rawCookies) = split (/; /,$ENV{'HTTP_COOKIE'});
    my %cookies;
    foreach(@rawCookies){
    my ($key, $val) = split (/=/,$_);
    $key =~ s/\s+//g;
    $val =~ s/\s+//g;
    $val =~ tr/+/ /;
    $val =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $cookies{$key} = $val;
    }
    return %cookies;
    }


    ------------------
    Activist News Network - Plebius Press - Nonprofit Directory

  2. #2
    SitePoint Member
    Join Date
    Feb 2000
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, I do know some basic perl, but what I want to do is to write a cgi that will set the http_referer as a cookie. How would that script look, basically? And can I then call that cgi using SSI to set the cookie?

    Also, I want to add a subroutine to another cgi script to retrieve that cookie and write it to a log file. Thoughts on that?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •