2

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?

sawa
  • 165,429
  • 45
  • 277
  • 381
user3843763
  • 259
  • 2
  • 5
  • It's what you want ? [How to run php code from inside a ruby script](http://stackoverflow.com/questions/3945509/how-to-run-php-code-from-inside-a-ruby-script) – Debflav Jul 16 '14 at 07:04
  • Yes. But as I think exec() method in ruby is for executing shell commands. Will it be usefull in running full php scripts? Like for example If i consider my Login.php file. Do I have to write **exec("php Login.php")** in my ruby script?? – user3843763 Jul 16 '14 at 07:10

1 Answers1

0

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.

Community
  • 1
  • 1