perl cgi set cookie issue

cookie value has some hex characters

Page 1 of 1

3 Replies - 2227 Views - Last Post: 20 February 2009 - 08:49 PM

#1 john2190  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-February 09

perl cgi set cookie issue

Post icon  Posted 20 February 2009 - 06:45 AM

#!c:\Perl\bin\perl.exe
use CGI ':standard';
use Win32::ODBC;

$Email = param('Email');

$cookie = $cgi_query->cookie(-name=>'userID',
						-value=>'SITE=http://www.example.com',
						-expires=>'+24h',
						-path=>'/');
 
#create the HTTP header and print the doc type
print $cgi_query->header(-cookie=>$cookie);

#print "Content-type: text/html\n\n";

print "<HTML>\n";



created cookie value='SITE%3Dhttp%3A%2F%2Fwww.example.com'

using Sambar6.2
I am missing something basic? I want the cookie value to not have the hex codes.
Thank-you for looking into my problem.

Is This A Good Question/Topic? 0
  • +

Replies To: perl cgi set cookie issue

#2 mocker  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 50
  • View blog
  • Posts: 466
  • Joined: 14-October 07

Re: perl cgi set cookie issue

Posted 20 February 2009 - 09:27 AM

The hex codes are used to CGI.pm, as it will automatically url encode any special characters in the value . When you fetch the value of a cookie using the CGI functions, it should decode it back into it's original form.
You can also use this regex to decode:
s/%(..)/pack('c', hex($1))/eg

If you for some reason need the actual cookie to not be url encoded, you can write the http headers manually without using CGI.pm, but you'll probably run into problems since SITE=urlblahblahblah looks like it's own name-value pair to the browser, as opposed to being one value that you are assigning to the cookie 'userID'
Was This Post Helpful? 0
  • +
  • -

#3 john2190  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-February 09

Re: perl cgi set cookie issue

Posted 20 February 2009 - 03:44 PM

View Postmocker, on 20 Feb, 2009 - 08:27 AM, said:

The hex codes are used to CGI.pm, as it will automatically url encode any special characters in the value . When you fetch the value of a cookie using the CGI functions, it should decode it back into it's original form.
You can also use this regex to decode:
s/%(..)/pack('c', hex($1))/eg

If you for some reason need the actual cookie to not be url encoded, you can write the http headers manually without using CGI.pm, but you'll probably run into problems since SITE=urlblahblahblah looks like it's own name-value pair to the browser, as opposed to being one value that you are assigning to the cookie 'userID'


Thank-you mocker. I am reading the cookie back with html javascript and then pass the value to flashmx as the application is in flash. I did not try reading the cookie back with perl cgi.pm. I guess I can pick up a java book and decode with that. To read the cookie back with perl cgi.pm will decode the cookie but then I am having problems getting the cookie value to flash. I also tried to write the cookie directly to the http headers but then reading it back with javascript I ran into domain issues and could not see it. Any suggestion for a simple solution?
Was This Post Helpful? 0
  • +
  • -

#4 john2190  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 20-February 09

Re: perl cgi set cookie issue

Posted 20 February 2009 - 08:49 PM

View Postjohn2190, on 20 Feb, 2009 - 02:44 PM, said:

View Postmocker, on 20 Feb, 2009 - 08:27 AM, said:

The hex codes are used to CGI.pm, as it will automatically url encode any special characters in the value . When you fetch the value of a cookie using the CGI functions, it should decode it back into it's original form.
You can also use this regex to decode:
s/%(..)/pack('c', hex($1))/eg

If you for some reason need the actual cookie to not be url encoded, you can write the http headers manually without using CGI.pm, but you'll probably run into problems since SITE=urlblahblahblah looks like it's own name-value pair to the browser, as opposed to being one value that you are assigning to the cookie 'userID'


Thank-you mocker. I am reading the cookie back with html javascript and then pass the value to flashmx as the application is in flash. I did not try reading the cookie back with perl cgi.pm. I guess I can pick up a java book and decode with that. To read the cookie back with perl cgi.pm will decode the cookie but then I am having problems getting the cookie value to flash. I also tried to write the cookie directly to the http headers but then reading it back with javascript I ran into domain issues and could not see it. Any suggestion for a simple solution?



I am good now as I found the javascript unescape function will decode the URL encoding and all seems to work now. Thanks to mocker for the assistance as you help get me thinking in better direction.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1