Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP invoking another script but through http (isolating them)

Tags:

php

Let's see if I make myself clear. I have an old set of scripts that run well on PHP4 and better don't thouch em. I have to integrate a new functionality implemented on PHP5, I need just to invoke a script on the new app from the old one.

To not have to touch the old stuff I think to somehow "kin of remotely" invoke the new one, need only to pass the $_REQUEST[] data. I can not include it as that would require migrating to another PHP version (and some name clashing). I don't need any output from the new one.

What would be the cleaner way to "call" that script passing parameters, fopen("http://theserver.com/thescript.php"....) and then passing all the necessary headers to pass the parameters? or there's somethign more direct?

Thanks!

like image 897
tru7 Avatar asked Sep 23 '10 11:09

tru7


2 Answers

If you need to pass POST data, you can use cURL; otherwise, you can just do file_get_contents('http://example.com/yourscript.php?param1=x&param2=y&param3=...'); and the HTTP wrapper will do the request for you (simplest way).

like image 110
Piskvor left the building Avatar answered Sep 27 '22 16:09

Piskvor left the building


You're going to give yourself nightmares with this.

But if you really need to do it, you're not going to be able to rely on fopen. I would recommend using cURL, as Piskvor suggests.

But please, make sure you're validating and escaping any data you're pushing across correctly, or you're in for a world of hurt - the fact that you're making a cURL request to the other part of the system means that in theory, anyone else can do exactly the same thing.

This is most definitely not a long term solution, I would advise you rewrite the old parts as a priority.

like image 33
Steve Hill Avatar answered Sep 27 '22 18:09

Steve Hill