Solved

Setting cookie when static page loads /SSI?

Posted on 2001-08-02
2
418 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
2 Comments
 
LVL 2

Accepted Solution

by:
shirjeel earned 50 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Perl, group, sort, count question 6 133
delete query using perl dbi 3 100
How to delete rows in a file based on the file name. 5 60
Call Shell Script from Perl Script 6 100
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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