Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem setting Cookies in Perl

Status
Not open for further replies.

simomofo

Programmer
Joined
Apr 11, 2007
Messages
1
Location
IE
I can't seem to set cookies in Perl no matter what.

These are the two ways I 've tried:

1) using CGI.pm

$cookie = $query->cookie(-name=>'DemoName',
-value=>'success',
-expires=>'+4h',
-path=>'/');

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

but all that does is print this at the start of the page:

Set-Cookie: DemoName=success; path=/; expires=Wed, 11-Apr-2007 15:48:20 GMT
Date: Wed, 11 Apr 2007 11:48:20 GMT
Content-Type: text/html; charset=ISO-8859-1


2) I have also tried using javascript:

<SCRIPT>

function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) \? argv[2] : null;
var path = (argc > 3) \? argv[3] : null;
var domain = (argc > 4) \? argv[4] : null;
var secure = (argc > 5) \? argv[5] : false;
document.cookie = name + \"=\" + escape (value) +
((expires == null) ? \"\" : (\"; expires=\" + expires.toGMTString())) +
((path == null) \? \"\" : (\"; path=\" + path)) +
((domain == null) \? \"\" : (\"; domain=\" + domain)) +
((secure == true) \? \"; secure\" : \"\");
}

var uname = 'success';
var expdate = new Date ();
expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000));
SetCookie('DemoName', uname, expdate);

</SCRIPT>

this script works perfectly in a normal html file, but just doesn't work when it's its returned with html in perl!!

please help!!! I am completely bewildered!!!!
 
Hi

simomofo said:
but all that does is print this at the start of the page:

Set-Cookie: DemoName=success; path=/; expires=Wed, 11-Apr-2007 15:48:20 GMT
That means, the HTTP response header was already sent. You must send cookies before start sending the content itself.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top