简体   繁体   English

如何将HTML表单输入传递给PHP,然后传递给Ruby?

[英]How do I pipe HTML form input into PHP and then to Ruby?

This probably seems stupid. 这可能看起来很愚蠢。 If it's non-achievable, please let me know. 如果无法实现,请告诉我。
So: I have a Rasperry Pi (RPi) that's running Raspbian and nginx for a simple home network fileshare server. 所以:我有一个Rasperry Pi(RPi),它为一个简单的家庭网络文件共享服务器运行Raspbian和nginx。 I mainly did this for learning, and dived straight into it. 我主要是为了学习而做的,然后直接学习。 Anyway, my login system is as follows: 无论如何,我的登录系统如下:

login.html: login.html:

<html>
...
<form action="cgi-bin/loginHandler.php">
    <label for="username">Username:</label>
    <input name="username">
    <br/>
    <label for="username">Password:</label>
    <input name="password">
    <input name="button" type="submit" value="Submit">
</form>
...
</html>

cgi-bin/loginHandler.php: cgi-bin / loginHandler.php:

<?php
exec("./login.rb $arg1 $arg2")
?>

cgi-bin/login.rb: cgi-bin / login.rb:

#!/usr/bin/ruby1.9.1
#update-alternatives changed "ruby" to "ruby1.9.1"

cmdArray = Array.new

ARGV.each do |a|
    cmdArray.push a
end

#backwards because I used push
if cmdArray[1] == "/u/afdsadf" and cmdArray[0] == "/r/unixporn"
    htmlFile = File.new("loggedIn.html", "w+")
    htmlFile.puts("<html><head></head><body>You are now logged in!</body></html>")
else
    htmlFile = File.new("notLoggedIn.html", "w+")
    htmlFile.puts("<html><head></head><body>You are now logged in!</body></html>")
end

I checked my cgi-bin directory, where there definitely was not a "loggedIn.html" or "notLoggedIn.html", so either the Ruby is throwing an error or not running at all. 我检查了我的cgi-bin目录,其中肯定没有“ loggedIn.html”或“ notLoggedIn.html”,因此Ruby抛出错误或根本没有运行。 Then again, using PHP was probably a bad idea in the first place. 再说一次,使用PHP首先可能不是一个好主意。 I also probably need a method in the form itself, but I wouldn't know what to use. 我可能还需要表单本身中的method ,但是我不知道该使用什么。

Try to use absolute paths instead: 尝试改用绝对路径:

exec("/path/to/login.rb $arg1 $arg2")

Or explicitly call ruby: 或显式调用ruby:

exec("/usr/bin/ruby /path/to/login.rb $arg1 $arg2")

Same for the files you try to open: 与您尝试打开的文件相同:

htmlFile = File.new("/path/to/loggedIn.html", "w+")
htmlFile = File.new("/path/to/notLoggedIn.html", "w+")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM