Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Cookies and Exec Cgi

by ThingFish (Beadle)
on Dec 26, 2001 at 21:26 UTC ( #134423=perlquestion: print w/ replies, xml ) Need Help??
ThingFish has asked for the wisdom of the Perl Monks concerning the following question:

I have a SIMPLE test script to print a message that states whether or not you have a cookie and then sets one if you don't. It works fine when called directly, but when called from the HTML with exec cgi, it only prints out the message and DOES NOT set a cookie. Any guess as to why this is hapenning? Thanks

Comment on Cookies and Exec Cgi
Re: Cookies and Exec Cgi
by merlyn (Sage) on Dec 26, 2001 at 21:40 UTC
    Yes. Serverside includes do not recieve the full header passed to the main script (so they cannot detect cookies), nor are they able to set cookies because their headers are mostly ignored. You'll need to come up with a different strategy.
Re: Answer: Cookies and Exec Cgi
by rob_au (Abbot) on Dec 27, 2001 at 06:04 UTC
    This has not been my experience Merlyn - Well, from the point of view of detecting cookies within server-side includes.

    I have a web site under construction that makes use of a cookie-based session system via by server side includes. For example, the index.shtml file calls a 'links' sidebar where authenticated users can set their own personal bookmark links, much like the personal nodelet on this site, whereas non-authenticated users are displayed a login form.

    The index.shtml server-side include looks like this:

    <!--#include virtual="/cgi-bin/links.cgi" -->

    Where the corresponding display_links dispatch subroutine of the links.cgi code, which uses CGI::Application, looks similar to this (cut a little for brevity):

    sub display_links { my $self = shift; my $cgi = $self->query; my $xml = $self->param('xml'); my %auth = $cgi->cookie( -name => 'cowsnet-auth', -path => '/' ); my $html; if (scalar keys %auth) { my $prefs = eval { my @user = grep { $_->{'username'} eq $auth{'username'} } +@{%{$xml}->{'user'}}; return shift @user; }; $html = $self->load_tmpl("authenticated.tmpl"); if (exists $prefs->{'links'}) { my @links; push (@links, { 'href' => eval { my $uri = URI->new($_->{'href'}); $uri->canonical->as_string; } }) foreach @{$prefs->{'links'}}; $html->param( 'links' => \@links ); } } else { $html = $self->load_tmpl("default.tmpl"); } return $html->output; }

    This works like a charm - In order to set cookies with this system however I do still resort to calling a CGI directly which redirects through to 'authentication' page.

     

    perl -e 's&&rob@cowsnet.com.au&&&split/[@.]/&&s&.com.&_&&&print'

    20060730 Unconsidered by Corion: Consideration impossible. Was considered by jdporter: reparent to its proper parent, Answer: Cookies and Exec Cgi. Not sure how it ended up in the wrong place...

Re: Cookies and Exec Cgi
by QwertyD (Pilgrim) on Jan 02, 2002 at 01:05 UTC
    You could try having your Perl script send JavaScript that sets a cookie. Alternatively, you could have the Perl script output an image and send the cookie along with the image, though some ad filters may block that cookie.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2014-10-25 13:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (143 votes), past polls