简体   繁体   中英

How to execute php script in a ruby file

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?

Hm, your "exec("php Login.php")" idea is interesting. 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. 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.

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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