Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variables within multiple scripts, single page request

Status
Not open for further replies.

csteinhilber

Programmer
Aug 2, 2002
1,291
US
We have a legacy PERL solution to build the UI on our webpages. We're migrating to a full CMS, but for the time being about 60% of our pages are still using something like:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
 
<title>A Page Title</title>
 
<meta name="description" content="About  Page" />
<meta name="doctype" content="General" />
<meta name="Last-Modified" content="2/01/00" />
   :
   : 
</head>
 
<!--#exec cmd="/cgi-bin/pageopen.cgi template=a1 nav=nav1 ad=ad001 login=yes" -->

<!-- BEGIN MAIN CONTENT AREA -->

Hello World

<!-- END MAIN CONTENT AREA -->
 
<!--#exec cmd="/cgi-bin/pageclose.cgi"-->
</html>

Pageopen builds the BODY tag, the UI header and left nav bar based on several parameters passed into it on the exec command.

Pageclose closes any DIVs, etc that Pageopen opened, and closes the BODY tag.

It's served us pretty well for many years.
But now I have a real need to have several of the variables that Pageopen uses/creates by accessible to Pageclose (without any rewrite to the exec commands).

What's the best way to do this?

So options I've been thinking about:

- having Pageopen open a session and store appropriate vars there (and have Pageclose read the vars then close the session so it doesn't hang around unnecessarily).

- somehow make Pageopen run persistantly, and maybe Pageclose would be able to read it's vars if it's still running (??)

- create some sort of unique ID, write variable values to a text file with that name, which Pageclose could then read. But the unique ID would have to be assembled from some server variables that both Pageopen and Pageclose could consistantly grab and arrive at the same value. Not sure what those "server variables" would be.

- have Pageopen store values into a cookie, which Pageclose could read. But our target audience is not fond of cookies (less fond of cookies than your average user), and we can't guarantee that cookies are are turned on.

- have Pageopen use javascript to write a hidden form field or something that Pageclose could read (but I'm not at all sure how Pageclose could read it)

- store values in the scope of the page request, somehow... since it's all a single page request. But I have no idea what scope that would be in terms of CGI/PERL.

Anyone else have any other ideas, or solutions for any of the alternatives above?

Any help would be greatly appreciated!

Thanks in advance,
-Carl
 
Have a look at
Storable.pm
CGI::Session

Storable should let you store a chucnk of data, and CGI::Session should let you create a session key to store in a cookie which you could access in page close, and look Storable from that

HTH
--Paul


It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
Are you using Apache? I don't think most of your proposed options will work, especially if you're staying away from cookies. But you may have something with "store values in the scope of the page request". I think this can be done if you're running Apache with mod_perl, though I'm not sure how. Perhaps by using the headers_in method to store the data in the headers hash? I didn't see a way to modify the request's args, I think you can only read them.

Another option is using HTML::Mason for your site. You'd have to do a bit of rewriting on your pages but I don't think it'd be too bad. Check out
 
Thanks to you two for your responses. Unfortunately I haven't hit on a solution yet.

It looks like I can't set a cookie (even if I wanted to) because the headers have already been written to the browser (by the HTML page that actually exec's the CGI).

If I try to
Code:
print "Set-Cookie: ..."
or
Code:
print header(-cookie=>...);

all I get is a nice print of my cookie data at the top of the browser window.

I think all I'm going to be able to do is either derive some kind of unique ID from something available in the ENV hash (or other global var) and use that with Storable.pm (SOMETHING somewhere must uniquely identify the page request, right??) or somehow write to the pages request scope.

Anyone have any ideas (or know how I'd be able to set a cookie)?

Thanks,
-Carl

 
Sorry... forgot (twice) to mention that this is on iPlanet.


-Carl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top