rshoe has asked for the wisdom of the Perl Monks concerning the following question:
The cookie cgi file<!doctype html> <html lang = "en"> <head> <title>Sign Up</title> </head> <body> <h2>Sign up and choose your options</h2> <form action="/cgi-bin/signup.cgi" method="post"> <table border="2" cellspacing="5" cellpadding="5"> <tr> <td align="center">Name</td> <td><input type="text" name="name" size="30"></td> </tr> <tr> <td align="center">Select MemberShip Type</td> <td><input type = "radio" name = "membership" value="0">Life <input type = "radio" name = "membership" value="1">Annual <input type = "radio" name = "membership" value="2">Fee Trial</td> </tr> <tr> <td align="center">Choose Background Color</td> <td><select name = "color"> <option value = "pk">Pink <option value ="cy">Cyan <option value = "ma">Magenta <option value ="wh">White <option value = "go">Gold <option value ="bl">Blue </select> </tr> <tr> <td colspan="2" align="center"><input type = "submit" value="Sign Up + and Set Options" </td> </tr> </form> </table> </body> </html>
The output cgi file#!c:\Dwimperl\perl\bin\perl.exe use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use strict; use warnings; my $name = param('name'); my $membership = param('membership'); my $color = param('color'); my @members = ('Life', 'Annual', 'Free Trial'); my %colors =(pk => 'Pink', cy => 'Cyan', ma => 'Magenta', wh => 'White', go => 'Gold', bl => 'Blue',); my @newmembers =($members[$membership], $name, $colors{$color}); my $mem = cookie(-name => "member", -value => "@newmembers", -path => "/", -expires => "+1M" ); print header( -cookie => [$mem] ), start_html, "<h2>Thank you. Your data has been recorded</h2>", "<a href='membership.cgi'>See member page</a>", end_html;
#!c:\Dwimperl\perl\bin\perl.exe use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use strict; use warnings; my @ara = split (/ /,cookie("member")); #### splits on spaces into ar +ray if($ara[0] =~ /Free Trial/){ print header, start_html; print "<body bgcolor ='".$ara[4]."'/>"; print "<h1>Welcome back, ".$ara[0]." ".$ara[1]." Member ".$ara[2]." ". +$ara[3]."</h1>"; print end_html; }else{ print header, start_html; print "<body bgcolor ='".$ara[3]."'/>"; print "<h1>Welcome back, ".$ara[0]." Member ".$ara[1]." ".$ara[2]."</h +1>"; print end_html; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regular Expressions in a cookie
by FloydATC (Deacon) on Oct 22, 2014 at 05:03 UTC | |
|
Re: Regular Expressions in a cookie
by tangent (Parson) on Oct 22, 2014 at 02:59 UTC | |
|
Re: Regular Expressions in a cookie
by Anonymous Monk on Oct 21, 2014 at 23:12 UTC |