Reputation: 26815
Is there a way to catch the contents of the PHP session variable $_SESSION['user_id']
with a mod_wsgi
Python script? I'm running a script in the background that will decide whether or not the user may proceed to view the document.
I would like to do something like this:
def allow_access(environ, host):
allow_access = False
if environ['SCRIPT_NAME'] == 'forbidden_dir':
if session['user_id'] == '1':
allow_access = True
if allow_access:
return True
else:
return False
Is it possible?
Upvotes: 0
Views: 550
Reputation: 319571
please don't do this:
if allow_access:
return True
else:
return False
when you can do: return allow_access
.
Upvotes: 3
Reputation: 1139
If it's possible, it's not easy; apache stores session variables in files in a special format.
Your best option might be to write a php page that prints all session variables. (Hard-code it to only serve to localhost.) Open the url to that page from within your python script. Add a header to the url request with the session info. Then, once the php page is loaded in Python, parse the input.
Upvotes: 3