PHP 到 Python 服务器页面、会话和 EXEC
我正在尝试将此 PHP 转换为 psp(python 服务器页面)。我对 php exec 函数和会话变量的 isset 感到不知所措。
session_start();
if(isset($_POST["var"])){
//set session username
$username = (string)$_POST["var"];
$username = trim($username);
$_SESSION['username'] = $username; //store $username
}
if(isset($_SESSION['username'])){
$username = $_SESSION['username']; //store session[username] as $username
$cmd = '/var/www/cgi-bin/resolveID.py ' . escapeshellcmd($username);
$fullname = exec($cmd);
$_SESSION['fullname'] = $fullname;
}
else{
echo 'Your session has expired, please click <a href="https://devh.test.com/">here</a>';
exit;
}
这就是我所拥有的
<%
import cgitb, session
cgitb.enable()
user_session = Session.Session()
#post info
if form.getvalue('var'):
varUsername = form.getvalue('var')
user_session['username'] = varUsername
#session set stuff
try:
if user_session['username']:
#is set
varUsername = user_session['username']
varCMD = '/var/www/cgi-bin/resolveID.py ' + varUsername
varFullname = subprocess.check_output(varCMD)
user_session['fullname'] = varFullname
except:
#not set
req.write('Your session has expired, please click <a href="https://dev.test.com/">here</a>')
%>
I'm trying to convert this PHP to psp(python server pages). I'm at a loss with the php exec function and isset for the session variables.
session_start();
if(isset($_POST["var"])){
//set session username
$username = (string)$_POST["var"];
$username = trim($username);
$_SESSION['username'] = $username; //store $username
}
if(isset($_SESSION['username'])){
$username = $_SESSION['username']; //store session[username] as $username
$cmd = '/var/www/cgi-bin/resolveID.py ' . escapeshellcmd($username);
$fullname = exec($cmd);
$_SESSION['fullname'] = $fullname;
}
else{
echo 'Your session has expired, please click <a href="https://devh.test.com/">here</a>';
exit;
}
This is what i have
<%
import cgitb, session
cgitb.enable()
user_session = Session.Session()
#post info
if form.getvalue('var'):
varUsername = form.getvalue('var')
user_session['username'] = varUsername
#session set stuff
try:
if user_session['username']:
#is set
varUsername = user_session['username']
varCMD = '/var/www/cgi-bin/resolveID.py ' + varUsername
varFullname = subprocess.check_output(varCMD)
user_session['fullname'] = varFullname
except:
#not set
req.write('Your session has expired, please click <a href="https://dev.test.com/">here</a>')
%>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为
subprocess.check_output()
是您正在寻找的函数:在 python 中,您使用
'key' in array
而不是isset($array['key'])
。I think
subprocess.check_output()
is the function you are looking for:Instead of
isset($array['key'])
you use'key' in array
in python.