Solved

Setting cookie when static page loads /SSI?

Posted on 2001-08-02
2
416 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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
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…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

763 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

12 Experts available now in Live!

Get 1:1 Help Now