Link to home
Start Free TrialLog in
Avatar of vasavi
vasavi

asked on

Cookie problem

Hi all,

I need to set a cookie in the client machine and then display some html content. The problem is, I am supposed to set the cookie using perl code which is an include file in a .shtml page.

Thanks in advance,
Vasavi.
Avatar of Peewee
Peewee

vasavi,

here is example use of setting a cookie within your perl script, there are many different ways of doing this:
 
use CGI qw/:standard/;
use CGI::Cookie;

    # Create new cookies and send them
    $cookie1 = new CGI::Cookie(-name=>'ID',-value=>123456);
    $cookie2 = new CGI::Cookie(-name=>'preferences',
                               -value=>{ font => Helvetica,
                                         size => 12 }
                               );
    print header(-cookie=>[$cookie1,$cookie2]);

============= feteching them ==================
    # fetch existing cookies
    %cookies = fetch CGI::Cookie;
    $id = $cookies{'ID'}->value;
    # create cookies returned from an external source
    %cookies = parse CGI::Cookie($ENV{COOKIE});

regards
Peewee

vasavi,

a further example of setting a cookie:

 $c = new CGI::Cookie(-name    =>  'foo',
                             -value   =>  'bar',
                             -expires =>  '+3M',
                             -domain  =>  '.capricorn.com',
                             -path    =>  '/cgi-bin/database'
                             -secure  =>  1
                            );

a good resource site for cooies is: http://www.cookiecentral.com/

regards Peewee
ASKER CERTIFIED SOLUTION
Avatar of Peewee
Peewee

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
vasavi,

please clean up the status of this question?


regards Peewee
Force Accepted

SpideyMod
Community Support Moderator @Experts Exchange