CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
COOKIES

 



jumaru
Deleted

Apr 7, 2000, 6:44 PM

Post #1 of 9 (1742 views)
COOKIES Can't Post

please show me how to use cookies (sending recovering...) in using cgi-lib.pl or CGI::Cookies
please


Cure
User

Apr 7, 2000, 7:05 PM

Post #2 of 9 (1742 views)
Re: COOKIES [In reply to] Can't Post

Hi

Sending the Cookie to the Browser

Within a CGI script you can send a cookie to the browser by creating
one or more Set-Cookie: fields in the HTTP header. Here is a typical
sequence:

my $c = new CGI::Cookie(-name => 'foo',
-value => ['bar','baz'],
-expires => '+3M');
print "Set-Cookie: $c\n";
print "Content-Type: text/html\n\n";


Recovering Previous Cookies

%cookies = fetch CGI::Cookie;

fetch returns an associative array consisting of all cookies
returned by the browser. The keys of the array are the cookie names. You
can iterate through the cookies this way:

%cookies = fetch CGI::Cookie;
foreach (keys %cookies) {
do_something($cookies{$_});
}

Cure

[This message has been edited by Cure (edited 04-07-2000).]


jumaru
Deleted

Apr 7, 2000, 7:48 PM

Post #3 of 9 (1742 views)
Re: COOKIES [In reply to] Can't Post

Dear Cure thanks
but it's the same things I read in the CGI::Cookie manual and it's not clear for me
I explain you what I wanna do:
I wanna send in the cookie "$url"
how to recover the value of $url later from the cookie ?



jumaru
Deleted

Apr 10, 2000, 5:36 PM

Post #4 of 9 (1742 views)
Re: COOKIES [In reply to] Can't Post

please help me
I need to know how to manipulate cookies
pleassssseeeeeeeee


Jasmine
Administrator / Moderator

Apr 10, 2000, 7:20 PM

Post #5 of 9 (1742 views)
Re: COOKIES [In reply to] Can't Post

To be able to manipulate the cookies, you first need to retrieve them, which is the

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>


%cookies = fetch CGI::Cookie;
foreach (keys %cookies) {
do_something($cookies{$_});
}
</pre><HR></BLOCKQUOTE>

portion of the code that was posted. All of the cookies will be in a hash named %cookie. From there, you can do whatever you need. If you need to change the cookie's value, update the %cookies hash, then reset the cookies.


jumaru
Deleted

Apr 11, 2000, 6:21 PM

Post #6 of 9 (1742 views)
Re: COOKIES [In reply to] Can't Post

Sorry Jasmine but it doesn't work for me


Cure
User

Apr 11, 2000, 6:57 PM

Post #7 of 9 (1742 views)
Re: COOKIES [In reply to] Can't Post

Hi jumaru:

Trying to figure out why its not working for you.

I'll give you another example that might be able to help you.

Okay lets say that you have a URL like this

www.thecure.com

and lets say you wanted to use a cookie to deal with the query string

So lets say now-> you have a url like this

www.thecure.com/cgi-bin/hope.cgi?cure

and you want to pass cure to your cookies

so make a script names hope.cgi and put this in the script

use CGI::Cookie;

$query=$ENV{'QUERY_STRING'};

$this = new CGI::Cookie (
-name => "ID",
-value => "$query",
-expires => "+3M", # 3 months

);

print "Set-cookie: $this\n";


Now pull up the hope.cgi script with this url

www.thecure.com/cgi-bin/hope.cgi?cure


Now you just created a cookie with a hash.

NOTE: cookies are a hash.

So the key is ID and the value is cure. AND the cookie will last 3 months.

Now lets say you wanted to retrieve that cookie then make put this in a cgi-script called retrieve.cgi.

#!/usr/bin/perl

use CGI;

$cookie = new CGI;

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

%answers = $cookie->cookie('ID');

print %answers;

This will find the key-> ID and print the value of that key to the browser...


I hoped that helps you.

Cure




jumaru
Deleted

Apr 12, 2000, 8:41 PM

Post #8 of 9 (1742 views)
Re: COOKIES [In reply to] Can't Post

It workkkkkksssss Smile
Thanks Cure
Sincerly thank U and thanks for all the perl Archive team
You're the best Smile


Cure
User

Apr 13, 2000, 1:46 PM

Post #9 of 9 (1742 views)
Re: COOKIES [In reply to] Can't Post

Your Welcome jumaru


Cure

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives