简体   繁体   English

如何在Ruby文件中执行PHP脚本

[英]How to execute php script in a ruby file

I created a web based application using PHP and MySQl. 我使用PHP和MySQl创建了一个基于Web的应用程序。 It has a login page Login.php , which is the starting page. 它有一个登录页面Login.php ,它是起始页面。 I want to integrate my php code in ruby code. 我想将我的PHP代码集成到ruby代码中。 I want to include this Login.php page in the ruby application so that it can display the page. 我想在红宝石应用程序中包含此Login.php页面,以便它可以显示该页面。 Is there any possible solution? 有没有可能的解决方案?

Hm, your "exec("php Login.php")" idea is interesting. 嗯,您的“ exec(“ php Login.php”)“想法很有趣。 But you should redirect the output then. 但是您应该然后重定向输出。 You can get the output like this: 您可以这样获得输出:

$output       = array();
$returnStatus = null;
$command      = 'php Login.php';
exec($command, $output, $returnStatus);

// Your output is now in the $output array.

See http://de2.php.net/manual/de/function.exec.php for further documentation. 有关更多文档,请参见http://de2.php.net/manual/de/function.exec.php Also keep in mind that the user which is used for your anonymous calls should have the permission to execute php from cli and has access to the file you need. 还请记住,用于您的匿名呼叫的用户应具有从cli执行php的权限,并有权访问所需的文件。 Things can get even more "funny" if you use IIS. 如果使用IIS,事情可能会变得更加“有趣”。

But since you are using ruby try this first: 但是由于您使用的是红宝石,请先尝试以下方法:

require 'net/http'

source = Net::HTTP.get('stackoverflow.com', '/index.html')

I got it from the following wuestion of another user: How to get the HTML source of a webpage in Ruby . 我是从另一个用户的以下意图中获得的如何在Ruby中获取网页的HTML源

Your code would look like this: 您的代码如下所示:

require 'net/http'

source = Net::HTTP.get('your-wesome-domain-or-maybe-localhost.com', '/Login.php')

Also alter the path of the second parameter if needed. 如果需要,还可以更改第二个参数的路径。

With this you should also be able to execute the script and get your HTML output by simply triggering it with ruby. 有了这个,您还应该能够通过简单地用ruby触发脚本来执行脚本并获取HTML输出。

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

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