Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 15th, 2001, 01:56 PM
Stenyj Stenyj is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 3 Stenyj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry

Hi,
I'm programming using PERL with CGI.
I've been trying to set cookies with the following script:

--------------------------------------------------------
#!/usr/bin/perl

use CGI;
use DBI;

$foo = new CGI;

$cookie = $foo->cookie(-name=>'name', -value=>'Random Name',
-name=>'city', -value=>'Random city',
-name=>'team', -value=>'some team',
-name=>'age', -value=>'old',
-expires=>'+1h',
-path=>'/');

print $foo->header(-cookie=>$cookie);

print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>Testing Cookies</TITLE>\n";
print "</HEAD>\n";

print "<BODY>\n";

print "The file ran properly.. but do you have a cookie set? Click
<A HREF=\"take_cookie.cgi\">HERE</A> to see if it worked.\n";

print "</BODY>\n";
print "</HTML>\n";

--------------------------------------------------------

Now, I must be doing SOMETHING wrong with that coding, because when I run the following script (which extracts and prints the cookies that are set) the only thing I get is "age=twenty". I've checked the cookies on my comp, and that is in fact all that has been set.

--------------------------------------------------------


#!/usr/bin/perl

use CGI;
use DBI;

$foo = new CGI;

print $foo->header;

print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>Cookie Extract Test</TITLE>\n";
print "</HEAD>\n";

print "<BODY>\n";

print "Here are all the cookies that were set earlier.\n";
print "<HR><PRE>\n";
$raw_cookie = $ENV{'HTTP_COOKIE'};
@cookies = split /;/, $raw_cookie;
foreach $cookie (@cookies) {
print $cookie, "\n";
}
print "</PRE>\n";
print "<HR>\n";

print "</BODY>\n";
print "</HTML>\n";

--------------------------------------------------------


Any help/advice/info is much appreciated.

Thanx in advance,
Stenyj

Reply With Quote
  #2  
Old March 15th, 2001, 02:30 PM
unobserved unobserved is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 11 unobserved User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to unobserved
I believe you need one of these

Code:
$cookie = $foo->cookie(-name=>'name',
                       -value=>'Random Name',
                       -expires=>'+1h', 
                       -path=>'/'); 

for each cookie. ie, you'd have a $cookie_name, $cookie_age, $cookie_city, etc.

Then
Code:
print $foo->header(-cookie=>$cookie_name,
                   -cookie=>$cookie_age,
                   -cookie=>$cookie_city); 


Just a suggestions. If all else fails, try saving one cookie like this:

Code:
$cookie = $foo->cookie(-name=>'all_info',
                       -value=>"name|city|age",
                       -expires=>'+1h', 
                       -path=>'/');


Then just split the all_info cookie at the pipes when you pull it back in.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Can't seem to get my CGI created cookies working right....


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT