LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-01-2010, 07:30 AM   #1
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Rep: Reputation: 30
problem with perl/cgi and cookie


I cannot set cookie in my page.
My procedure is:

Quote:
#!/usr/bin/perl

use CGI;
use CGI::Carp qw(fatalsToBrowser);
use DBI;
use Template;

my $cgi = CGI->new();

print $cgi->header(-type => 'text/html');

my $cookie = $cgi->cookie(-name => 'sessionID', -value => 'user@networkstore', -expires => '+1h');
my $mycookie = $cgi->cookie('sessionID');

print $cgi->header(-cookie => $mycookie);
but I am not able to set $mycookie variable.

Where is the problem?

Thanks in advance for answers.
Savio
 
Old 03-01-2010, 09:36 AM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
How many cookies are you setting ?
$mycookie isn't defined correctly.

http://devdaily.com/perl/edu/articles/pl010012/
 
Old 03-01-2010, 11:52 AM   #3
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Original Poster
Rep: Reputation: 30
My new code is:
Quote:
#!/usr/bin/perl -w
use strict;

use CGI;
use CGI::Carp qw(fatalsToBrowser);

my $cgi = CGI->new();
my $cookie = $cgi->cookie(-name => 'sessionID', -value => 'user@networkstore', -expires => '+1h');
print $cgi->header(-type => 'text/html', -cookie => '$cookie');

my $mycookie = $cgi->cookie('sessionID');

if ("$mycookie") {
print "<h2>Your cookie is $mycookie</h2>";
}
else {
print "<h2>$mycookie is not set</h2>";
}
and output is:

is not set
 
Old 03-01-2010, 01:10 PM   #4
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
$mycookie isn't defined correctly.
And you have to declare the cookie before the headers.
What is the output of
Code:
if ("$cookie") {
print "<h2>Your cookie is $cookie</h2>";
}
else {
print "<h2>$cookie is not set</h2>";
}
 
Old 03-01-2010, 01:21 PM   #5
shifter
Member
 
Registered: May 2006
Distribution: Slackware, DragonFly
Posts: 233

Original Poster
Rep: Reputation: 30
Ok, thank you very much!
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with perl modules declaration and perl/cgi script shifter Programming 9 02-24-2010 09:09 AM
problem with cgi and perl shifter Programming 21 01-04-2010 05:42 PM
problem with perl ::CGI varala_kanth Linux - Software 0 05-10-2006 03:45 AM
HELP:perl CGI problem supermyself Programming 2 06-12-2005 08:34 AM
CGI -PERL Problem!!! lewkh Fedora 3 05-10-2005 12:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration