Passing variables between scripts

J Donald jeddak at mailbox.bellatlantic.net
Sun Jul 23 12:26:17 EDT 2000


If you're running on Unix or Linux, you can use environmental variables.

1. In cgi1.py, define an environmental variable that's unique to your
application,
2. make it available to all other sessions
3. put the value in that environmental variable
4. n cgi2.py, look for that environmental variable, and read in the value

Caveats:

1. This approach should only be used when your cgi is running in single-threaded
(i.e. one request/one cgi instance at a time).
2. Don't use environmental variables this way if you care about security.

Bjorn Pettersen wrote:

> Olav Viken wrote:
> >
> > Can anyone tell me if there is a good way to pass a variable between two CGI
> > scripts?
>
> There are many variations of this, but you can do a lot with the
> following model:
>
>   form1 -> cgi1 -> form2 -> cgi2
>
> meaning that your starting html page contains form1. When submitting the
> form, you call cgi1 which during it's processing prints form2. When
> form2 is submitted it calls cgi2.
>
> If you only have simple values (and don't require a very secure system),
> cg1 can print out a <input type="hidden" name="foo" value="%s"> tag
> where you substitute the %s for the repr of a dictionary containing all
> the values you want to pass.  You can then use eval on the value in cgi2
> to resurrect the dictionary (as I said, not particularly safe, but easy
> ;-)
>
> hth,
> -- bjorn
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jeddak.vcf
Type: text/x-vcard
Size: 172 bytes
Desc: Card for J Donald
URL: <http://mail.python.org/pipermail/python-list/attachments/20000723/3300ef10/attachment.vcf>


More information about the Python-list mailing list