Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can perl be used for cookie setting?

0 views
Skip to first unread message

Danny

unread,
May 2, 2004, 2:00:13 PM5/2/04
to
I wrote some javascript to retrive/set cookie for user.
The code just puts the reffering id passed in URL somewhere on the website
for tracking purposes.

I don't like how the code can be seen by all users if the wanted to. I
would also prefer something server side.
Is there a way I can use PERL to create a cookie in the same fashion?
Just put a call to a cgi script in the header or body of all web pages to
return the cookie info or set it if need be.

Thanks in advance


Gunnar Hjalmarsson

unread,
May 2, 2004, 2:04:40 PM5/2/04
to
Danny wrote:
> Is there a way I can use PERL to create a cookie in the same
> fashion? Just put a call to a cgi script in the header or body of
> all web pages to return the cookie info or set it if need be.

I suppose you can use SSI to include a CGI script that gets or sets a
cookie.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Randal L. Schwartz

unread,
May 2, 2004, 2:41:24 PM5/2/04
to
>>>>> "Gunnar" == Gunnar Hjalmarsson <nor...@gunnar.cc> writes:

Gunnar> Danny wrote:
>> Is there a way I can use PERL to create a cookie in the same
>> fashion? Just put a call to a cgi script in the header or body of
>> all web pages to return the cookie info or set it if need be.

Gunnar> I suppose you can use SSI to include a CGI script that gets or sets a
Gunnar> cookie.

SSI cannot set cookies. The headers of an SSI are checked for
well-formedness, but otherwise mostly ignored (other than redirects).
This includes the cookie-setting information. THus, no cookies.

print "Just another Perl hacker,"; # the first

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<mer...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Danny

unread,
May 2, 2004, 3:11:54 PM5/2/04
to

"Randal L. Schwartz" <mer...@stonehenge.com> wrote in message
news:67550059482efeed...@news.teranews.com...


Yes I am new to perl.
I cannot change the extensions of all of my html files.
So I need something that gets called automatically as the html page is
loaded.
I also need to pass a variable to and from the cgi script.
This needs to be done transparaently.
I would greatly appreciate your advice or perhaps some direction as to how
to go about this.

Thanks so much

Danny


@infusedlight.net Robin

unread,
May 2, 2004, 4:34:58 PM5/2/04
to

"Danny" <danny...@hotmail.com> wrote in message
news:NGalc.93810$Gd3.22...@news4.srv.hcvlny.cv.net...

See perldoc CGI! Your probably going to have to set the cookie with a cgi
script, so perhaps use the script and then redirect to your html page with
print redirect.
Good luck!

-Robin

Scott Bryce

unread,
May 2, 2004, 5:00:00 PM5/2/04
to
Danny wrote:

> Is there a way I can use PERL to create a cookie in the same fashion?
> Just put a call to a cgi script in the header or body of all web pages to
> return the cookie info or set it if need be.

Assuming this is being done in a CGI script...

To set the cookie you want to send a Set-Cookie header to the browser.
Do a Google search on http headers to get the correct syntax. It will
look something like this:

print "Set-Cookie:SessionID=$session_id\n";

To get cookies, read the docs for CGI.pm.

Gunnar Hjalmarsson

unread,
May 2, 2004, 5:11:39 PM5/2/04
to
Danny wrote:
> Randal L. Schwartz wrote:

>> Gunnar Hjalmarsson wrote:
>>> Danny wrote:
>>>> Is there a way I can use PERL to create a cookie in the same
>>>> fashion? Just put a call to a cgi script in the header or
>>>> body of all web pages to return the cookie info or set it if
>>>> need be.
>>>
>>> I suppose you can use SSI to include a CGI script that gets or
>>> sets a cookie.

>>
>> SSI cannot set cookies. The headers of an SSI are checked for
>> well-formedness, but otherwise mostly ignored (other than
>> redirects). This includes the cookie-setting information. THus,
>> no cookies.

Hmm.. You learn something new every day. :) Thanks, Randal!

> Yes I am new to perl.

That's okay. Note that your problem has nothing to do with the
programming language Perl.

> I cannot change the extensions of all of my html files. So I need
> something that gets called automatically as the html page is
> loaded.

That could still have been an SSI invoked script, provided that you
are able to modify the server configuration with e.g. an .htaccess
file. But now we know that SSI cannot be used for other reasons.

> I also need to pass a variable to and from the cgi script. This
> needs to be done transparaently.

Sorry, but it's not clear to me what you mean by that.

This group is for discussing Perl, so this thread is off topic here.
To increase your chances to get help, I would recommend that you post
in a more suitable group, such as comp.infosystems.www.authoring.cgi.
If you do, please try to include a better description of what it is
you are trying to accomplish. (Also, don't forget to study
http://www.thinkspot.net/ciwac/howtopost.html if you haven't posted to
comp.infosystems.www.authoring.cgi before.)

Joe Smith

unread,
May 3, 2004, 4:42:46 AM5/3/04
to
Danny wrote:

> I cannot change the extensions of all of my html files.
> So I need something that gets called automatically as
> the html page is loaded.
> I also need to pass a variable to and from the cgi script.
> This needs to be done transparaently.

You could do like what Sun did back in the early days of the www.

Instead of having URLs like http://www.sun.com/products/solaris.html
they had http://www.sun.com/show/products/solaris.html where
"show" is actually a CGI with an aliased name. The "show" program
used $ENV{PATH_TRANSLATED} to locate the plain HTML file. It then
added HTTP headers and HTML for navigation to everything it output.

-Joe

Randal L. Schwartz

unread,
May 3, 2004, 9:11:22 AM5/3/04
to Scott Bryce
>>>>> "Scott" == Scott Bryce <sbr...@scottbryce.com> writes:

Scott> print "Set-Cookie:SessionID=$session_id\n";

Please. Space after the colon. That it "works" with some so-called
browsers doesn't mean it's correct.

Scott> To get cookies, read the docs for CGI.pm.

Or to set cookies, read the docs for CGI.pm, and then you wouldn't
have made your syntax mistake, because CGI.pm does it properly. :)

Scott Bryce

unread,
May 3, 2004, 10:37:40 AM5/3/04
to
Randal L. Schwartz wrote:

>>>>>>"Scott" == Scott Bryce <sbr...@scottbryce.com> writes:
>
>
> Scott> print "Set-Cookie:SessionID=$session_id\n";
>
> Please. Space after the colon. That it "works" with some so-called
> browsers doesn't mean it's correct.

I don't know if I learn more from lurking, or from having my posts
corrected! Thanks! That line came directly from one of my CGI scripts.
It "works" for IE, NS and Opera. I'll certainly make the correction!

@infusedlight.net Robin

unread,
May 5, 2004, 2:24:34 AM5/5/04
to

"Danny" <danny...@hotmail.com> wrote in message
news:NGalc.93810$Gd3.22...@news4.srv.hcvlny.cv.net...

btw, my latest post has some examples of cookies and CGI.pm...
-Robin


0 new messages