Welcome to WebmasterWorld Guest from 54.242.173.65

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Cookies script not working

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

New User

5+ Year Member

joined:Sept 3, 2008
posts:4
votes: 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]

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

Preferred Member

10+ Year Member

joined:Jan 5, 2006
posts:536
votes: 0


probably you need to change this line:

$color = cookie('Color');

to:

$color = param('Color');

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

New User

5+ Year Member

joined:Sept 3, 2008
posts:4
votes: 0


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

New User

5+ Year Member

joined:Sept 3, 2008
posts: 4
votes: 0


Solution solved!

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

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

Administrator

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

joined:Aug 10, 2004
posts:10550
votes: 10


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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members