Solved

Setting cookie when static page loads /SSI?

Posted on 2001-08-02
2
417 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

914 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now