Welcome to WebmasterWorld Guest from 54.144.48.252

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Cookies script not working

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

5+ Year Member



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]

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

5+ Year Member



probably you need to change this line:

$color = cookie('Color');

to:

$color = param('Color');

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

5+ Year Member



I tried that and not working.
7:44 pm on Sep 3, 2008 (gmt 0)

5+ Year Member



Solution solved!

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

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

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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

Featured Threads

Hot Threads This Week

Hot Threads This Month