Welcome to Dream.In.Code
Getting Help is Easy!

Join 131,348 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,646 people online right now. Registration is fast and FREE... Join Now!




How to set perl cookies?

 
Reply to this topicStart new topic

How to set perl cookies?

derek.alarm
post 26 Sep, 2008 - 08:16 PM
Post #1


New D.I.C Head

*
Joined: 26 Sep, 2008
Posts: 1

After one page fully shows,I get some datas,then I want to pass them to the next page.One method is using cookie,but perl CGI must set cookie before the page's header,and I don't like to use query_string and cannot use session,How can I pass these data?Thanks a lot!
User is offlineProfile CardPM

Go to the top of the page


PsychoCoder
post 26 Sep, 2008 - 10:21 PM
Post #2


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,892



Thanked 115 times

Dream Kudos: 8450

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.

Here, to help some here are the basics of setting and reading cookie with Perl

Setting Cookies With Perl

1.) Create a new CGI object
python

use CGI;
$cgi_query = new CGI;


2.) Create your cookie using the cookie() method in Perl. In this example we will create a cookie named SITE_COOKIE with a value of SITE=http://www.example.com and it will expire in 24 hours. You use the cookie() method before calling the header() method

python

$cookie = $cgi_query->cookie(-name=>'SITE_COOKIE',
-value=>'SITE=http://www.example.com',
-expires=>'+24h',
-path=>'/');



3.) Create the HTTP header and print the doctype
python

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


Reading Cookies With Perl

1.) Create a new CGI Object
python

use CGI;
$cgi_query = new CGI;


2.) Create the HTTP header and print the doctype statement
python

print $cgi_query->header;


3.) Start the HTML doc, and give the page a title
python

print $cgi_query->start_html('My cookie-get.cgi program');


4.) Retrieve the cookie. Do this by using the cookie() method without the -value parameter.
python

print $cgi_query->h3('The cookie is ...');
$theCookie = $cgi_query->cookie('SITE_COOKIE');


Now you have a variable, $theCookie that holds the name and value of your cookie. That should at least get you headed down the right path. Happy coding! smile.gif

NOTE:

I know all the code blocks were done in Python. I did this because there doesn't seem to be support for syntax highlighting for Perl, so I used Python for better syntax highlighting for my example code smile.gif
User is offlineProfile CardPM

Go to the top of the page

KevinADC
post 27 Sep, 2008 - 07:18 AM
Post #3


D.I.C Head

Group Icon
Joined: 23 Jan, 2007
Posts: 212



Thanked 3 times

Dream Kudos: 50
My Contributions


QUOTE(derek.alarm @ 26 Sep, 2008 - 09:16 PM) *

After one page fully shows,I get some datas,then I want to pass them to the next page.One method is using cookie,but perl CGI must set cookie before the page's header,and I don't like to use query_string and cannot use session,How can I pass these data?Thanks a lot!


Get the data before the page fully loads, set the cookie, then print any visual elements to the page.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/19/08 04:26PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month