Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Setting cookie when static page loads /SSI?

Posted on 2001-08-02
2
Medium Priority
?
424 Views
Last Modified: 2012-05-04
I want to be able to set a cookie using a Perl script when a static page loads.

I've created a simple script that takes care of setting and reading the cookies (this calls subprocedures in a library that actually does the work):

#-----------------------
require 'pei_pgs.pl';

    $cid = time * int(rand(100000));
    if (&GetCookies('id')) {
            $visit = "old";
     $id = $Cookies{'id'};
    }else{
     &SetCookies('id',$cid);
     $visit = "new";
     $id = $cid;
    }
#test the results
print "Cookie $id, visit $visit";
#--------------------------------

It works just fine on the dynamic pages that I build at runtime.

However, we have a couple of dozen static pages on the site, and I want to be able to call the same script to set and read cookies when users access them.  I know I can set/read the cookies using JavaScript, but I wanted to be able to use the same Perl script on all of the pages.

I've been trying to do this using SSI:

<!--#exec cgi="../cgi-bin/setcookie.cgi"-->

I can read the cookie if one already exists, this part works just fine.  The problem is that I can't set a cookie using the script.  I know the script is executing OK, because it also does some log file updates (not shown here) and these are working fine.  It returns the value for $id and $visit, and it acts like the cookie got sent, but the browser never recieves it.  I'm assuming this is because I'm calling the script from one directory, and the page lives in a different one? Maybe the cookie just doesn't know where to go? Setting the cookie's path variable doesn't help, because this only tells the cookie where it is valid.

So the page lives in:
<home>/test_pages/cookie_test.shtml

But the script that is calling the cookie is in:
<home>/cgi-bin/setcookie.cgi

It seems like there should be a simple way to do this, and that I'm just missing something brainless. Maybe I'm barking up the wrong tree trying to use SSI to do this, but it seems like this would be a common issue.

Any help would be appreciated.

David
0
Comment
Question by:davidcanfield
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
shirjeel earned 200 total points
ID: 6346700
Dear davidcanfield,

Try the scripting of perl. I mean where u write

<script language="javascript"> write perl instead of java script. like this.

<script language="perl/perlscript">

Now write the same code here i think it will work for u. Hopefully.

Try this and then let me know.

Regards,
Shirjeel.
 
0
 

Author Comment

by:davidcanfield
ID: 6349634
Shirjeel;

Hmmm...didn't know you could do that with Perl scripts(cool).

I did this:

<script language="perl/perlscript" src = "../cgi-bin/name-of-script.cgi"></script>

I placed it in the body of the html, and it worked (after I placed the content header in the script).

Thanks for your help!

David

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question