0

my question is how i can send a parameter to script in a another server in php language? example: my site is: http://www.site.com/panel.php and i want to send some parameters to: http://www.site2.com/scirpt.pl and a srcipt run with parameters that given from php code and send a number or string to panle.php i think beter to user cgi in perl to get parameters and execute but i dont have backgrund from perl cgi and sorry for my bad language :D

IR4N0nY
  • 25
  • 1
  • 9
  • could you not use a query string... http://www.site2.com/scirpt.pl?var1=value1&var2=value2&var3=value3 im not sure if they work with perl but that would be an easy option – mic Mar 13 '14 at 18:35
  • So, just to clarify you want to call the perl script with a php script that makes a http call to the perl script through the server or do you want the php script to make a shell call to the perl script passing arguments in the call? – alexmac Mar 13 '14 at 18:37
  • Why not just have a common code base, php or Perl. This lowers your skill set to maintain the code base, unless this is your learning projects then no objections, it is helpful to understand how each works as a learning tool. – alexmac Mar 13 '14 at 18:38
  • @alexmac i want to the php script to make a shell call to the perl script and script do some thing with argument that given form php script – IR4N0nY Mar 14 '14 at 18:48

1 Answers1

0

If you're wanting to do a shell call, it gets a little tricky. Passing a shell call across servers (different machines) poses a security risk, as you wouldn't want me to be able to run a script on your machine from my shell. There are protocols, such as SSH, that would allow you to connect and make that shell call given the right configuration. Calling this from Perl or PHP, you would use backticks `` [Perl] or a system() [Perl, PHP] call to ssh with arguments that instruct it to run commands on the remote machine, then manipulate the standard output for display on the page the user sees.

It would be easier to copy the Perl script to the same server as the PHP script, depending on the permissions you have on each server. If this is possible, you can skip the ssh step and move straight into making the command call.

When doing anything with server side scripting, especially when executing code, it is important to keep security in mind. I recommend you filter all user input thoroughly to avoid having people execute code on your system. If you need help, look at PHP's filter_var() and Perl's regular expression capabilities. If you really want something to double check your security use Perl's taint mode as well.

As someone mentioned before in a comment, keeping your code in a standard language base could make it easier to orchestrate whatever you're trying to do. One other option, although it defeats your purpose of parsing input with one script and not with another, is to make a call to curl or wget and pass the "arguments" as get or post variables in the HTTP request. This requires you to filter on both ends, as someone could make a request from either script directly.

Community
  • 1
  • 1
fraz
  • 26
  • 4
  • I know this answer came a little later than the original poster had hoped, but I was Googling Perl stuff for a project and found something I thought I could actually help with, and wanted to contribute to StackOverflow for once. I hope it helps someone. – fraz Jul 08 '15 at 13:57