in reply to Re^6: Cookie->fetch problem
in thread Cookie->fetch problem
Here is a small perl cookie test script. Put this cookietest.cgi in the same folder as manage_users.cgi. Access with browser and click the create button several times to see cookies created. Then repeat press the refresh button to see them expire after 20 seconds and disappear. This should show whether the problem is with your script, browser or server.
poj#!/usr/bin/perl # cookietest.cgi use strict; use CGI ':standard'; use CGI::Cookie; use Data::Dumper; my $time = scalar localtime; my $cookie; if ( param('action') ){ $cookie = new CGI::Cookie( -name => (sprintf "TESTCOOKIE_%05d",rand(10000)), -value => $time, -expires => '+20s' ); CGI::delete_all(); print redirect( -cookie => $cookie ); } my $JS =<<EOJ; function display_ct() { var x = new Date() document.getElementById('ct').innerHTML = x; } EOJ print header( -cookie => $cookie ), start_html( -title => "cookietest.cgi", -script=>$JS, -onLoad=>"display_ct();" ), h2("Cookie Test"), h3("Server time is : $time"), h3("Client time is : <span id='ct' ></span>"); print start_form( -method => "POST" ); print submit("action","create cookie"); print submit("refresh","refresh"); print end_form; my %cookie = CGI::Cookie->fetch; my $count = keys %cookie; print h3("There are $count cookies"); print pre( Dumper \%cookie ),end_html;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Cookie->fetch problem
by huck (Prior) on Mar 12, 2017 at 00:42 UTC | |
by Anonymous Monk on Mar 12, 2017 at 04:32 UTC |