PHP 到 Python 服务器页面、会话和 EXEC

发布于 2024-10-20 01:21:41 字数 1345 浏览 1 评论 0原文

我正在尝试将此 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘴硬脾气大 2024-10-27 01:21:41

我认为 subprocess.check_output() 是您正在寻找的函数:

fullname = subprocess.check_output(['/var/www/cgi-bin/resolveID.py', username])

在 python 中,您使用 'key' in array 而不是 isset($array['key'])

I think subprocess.check_output() is the function you are looking for:

fullname = subprocess.check_output(['/var/www/cgi-bin/resolveID.py', username])

Instead of isset($array['key']) you use 'key' in array in python.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文