如何在ruby文件中执行php脚本

时间:2023-01-20 01:13:39

I created a web based application using PHP and MySQl. It has a login page Login.php, which is the starting page. I want to integrate my php code in ruby code. I want to include this Login.php page in the ruby application so that it can display the page. Is there any possible solution?

我使用PHP和MySQl创建了一个基于Web的应用程序。它有一个登录页面Login.php,它是起始页面。我想将我的PHP代码集成到ruby代码中。我想在ruby应用程序中包含此Login.php页面,以便它可以显示页面。有没有可能的解决方案?

1 个解决方案

#1


0  

Hm, your "exec("php Login.php")" idea is interesting. But you should redirect the output then. You can get the output like this:

嗯,你的“exec(”php Login.php“)”的想法很有趣。但是你应该重定向输出。你可以得到这样的输出:

$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. 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. Things can get even more "funny" if you use IIS.

有关更多文档,请参见http://de2.php.net/manual/de/function.exec.php。还要记住,用于匿名调用的用户应该具有从cli执行php的权限,并且可以访问您需要的文件。如果你使用IIS,事情会变得更加“有趣”。

But since you are using ruby try this first:

但是,因为你正在使用ruby首先尝试这个:

require 'net/http'

source = Net::HTTP.get('*.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输出。

#1


0  

Hm, your "exec("php Login.php")" idea is interesting. But you should redirect the output then. You can get the output like this:

嗯,你的“exec(”php Login.php“)”的想法很有趣。但是你应该重定向输出。你可以得到这样的输出:

$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. 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. Things can get even more "funny" if you use IIS.

有关更多文档,请参见http://de2.php.net/manual/de/function.exec.php。还要记住,用于匿名调用的用户应该具有从cli执行php的权限,并且可以访问您需要的文件。如果你使用IIS,事情会变得更加“有趣”。

But since you are using ruby try this first:

但是,因为你正在使用ruby首先尝试这个:

require 'net/http'

source = Net::HTTP.get('*.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输出。