homepage Welcome to WebmasterWorld Guest from 54.227.5.234
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Cookies script not working
perlnewbie




msg:3737115
 7:27 am on Sep 3, 2008 (gmt 0)

I'm trying to store cookies but its not working with the code I have. Do anyone see any errors?

<!c11ex4.html>
<HTML>
<HEAD><TITLE>Example Designs</TITLE></HEAD>
<BODY>
<H1>Select a Background Color</H1>
<FORM ACTION="http://servername.example.com/cgi-bin/c11/c11ex4a.cgi" METHOD=GET>
<P>
<INPUT TYPE=radio NAME=Color VALUE=hotpink>Pink<BR>
<INPUT TYPE=radio NAME=Color VALUE=silver>Silver<BR>
<INPUT TYPE=radio NAME=Color VALUE=tan>Tan<BR>
<INPUT TYPE=radio NAME=Color VALUE=white>White<BR>
</P>
<INPUT TYPE=submit VALUE="Color Choice">
</FORM></BODY></HTML>
---------------------
#!/user/bin/perl
#c11ex4a.cgi - first script
use CGI qw(:standard);
#prevent Perl from creating undeclared variables
use strict;
#declare and assign value to variable
my ($color, $C_color);
$color = cookie('Color');
#create and send cookie
$C_color = cookie(-name => "Color",
-value => "$color";
-path => "/cgi-bin/c11");
print header(-cookie => $C_color);
#create Web page
print "<HTML>\n";
print "<HEAD><TITLE>Example Designs</TITLE></HEAD>\n";
print "<BODY BGCOLOR=$color>\n";
print "<HR>\n";
print "<FORM ACTION='http://servername.example.com/cgi-bin/c11/c11ex4b.cgi' METHOD=POST>\n";
print "<H1>Example Designs</H1>\n";
print "<I>Welcome to our Web site!</I><BR><BR><BR>\n";
print "<INPUT TYPE=submit VALUE='Go to Next Page'>\n";
print "</FORM>\n";
print "</BODY></HTML>\n";
---------------------
#!/user/bin/perl
#c11ex4b.cgi - second script
print "Content-type: text/html\n\n";
use CGI qw(:standard);
#prevent Perl from creating undeclared variables
use strict;
#declare variable
my $color;
#assign value to variable and retrieve Color cookie
$color = cookie('Color');
#create Web page
print "<HTML>\n";
print "<HEAD><TITLE>Example Designs</TITLE></HEAD>\n";
print "<BODY BGCOLOR=$color>\n";
print "<HR>";
print "<H1>Example Designs</H1>\n";
print "<I>Thank you for visiting our Web site!</I>\n";
print "</BODY></HTML>\n";

[edited by: coopster at 2:00 pm (utc) on Sep. 3, 2008]
[edit reason] exemplified url and details [/edit]

 

perl_diver




msg:3737531
 5:33 pm on Sep 3, 2008 (gmt 0)

probably you need to change this line:

$color = cookie('Color');

to:

$color = param('Color');

perlnewbie




msg:3737550
 5:58 pm on Sep 3, 2008 (gmt 0)

I tried that and not working.

perlnewbie




msg:3737662
 7:44 pm on Sep 3, 2008 (gmt 0)

Solution solved!

[edited by: phranque at 4:31 am (utc) on Sep. 5, 2008]
[edit reason] notification [/edit]

phranque




msg:3738829
 4:34 am on Sep 5, 2008 (gmt 0)

i'm waiting, holding my breath, turning blue now...
=8)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved