Can perl be used for cookie setting?

D

Danny

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
 
G

Gunnar Hjalmarsson

Danny said:
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.
 
R

Randal L. Schwartz

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
 
D

Danny

Randal L. Schwartz said:
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
<[email protected]> <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!


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
 
R

Robin

Danny said:
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.

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
 
G

Gunnar Hjalmarsson

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.)
 
J

Joe Smith

Danny said:
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
 
R

Randal L. Schwartz

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. :)

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

Robin

Danny said:
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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top