[Tutor] RE: What file is calling the cgi ???

runsun runsun@bilbo.bio.purdue.edu
Sat, 3 Aug 2002 12:28:13 -0500


Hi all,

Last week I asked a question "What file is calling the cgi?"
(Tutor Digest, vol 1 # 1794, 7/28/02, Topic#3) but got no
answer.

I've found a way to get this info so here it is to share:

In the ???.shtml file that is calling the cgi (lets say,
/testfolder/caller.shtml), instead of using

      <!--#include virtual="/cgi-bin/py/whocalledme.py" -->,

using the following instead:

      <script language=javascript>
      document.write("<img src=/cgi-bin/py/whocalledme.py?" +
document.location+ " width=0 height=0>")
      </script>

This will get the whocalledme.py to run with arguement
sys.argv[1] = /testfolder/caller.shtml. You then can parse
that string for some further usage.

pan


] I have a cgi:
]
] 	/cgi-bin/py/whocalledme.py
]
] It was called by a shtml file "caller.shtml" as such:
]
]     <!--#include virtual="/cgi-bin/py/whocalledme.py" -->
]
] The full path name of "caller.shtml" is:
]
] 	/testfolder/caller.shtml
]
] Now, what code should I put in the whocalledme.py such
] that its execution (when called by caller.shtml) displays
] the folder name ('testfolder') and the caller name
] ('caller.shtml') on a browser ???
]
] Here were somethings I tried but they seem to offer the
] host info (namedly, /cgi-bin/py/whocalledme.py, but not
] /testfolder/caller.shtml) :
]
]      print os.getcwd()
]      print "<br>", os.environ.get("HTTP_REFERER", "--noreferer--")
]      print "<br>", os.environ.get("HTTP_HOST", "--nohost--")
]      print "<br>", os.curdir
]      print "<br>", os.path.abspath(os.curdir)
]
] I could have used:
]
]    <!--#include virtual="/cgi-bin/py/whocalledme.py?caller.shtml" -->
]
] but I really want to see if a python cgi can get the caller's name.
]
] Thx in advance.
]
] pan
]
]
] ============================================
]   ~~ Be like water, be shapeless ~~
]    Runsun Pan, PhD, 773-834-3965
]  Ecology & Evolution, U of Chicago
] ============================================