Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call PHP script from another PHP script?

Tags:

php

I have a PHP script, say a.php, which is called from JS using Ajax (this is a POST request and some data is passed to the script).

I have another PHP script, say b.php, from which I would like to call a.php and pass it some data. I expect a.php to do the job just like if it was called from JS.

I don't want to do include('a.php'); because of possible collision between variable names.

How could I do this ?

like image 240
Misha Moroshko Avatar asked Sep 25 '26 02:09

Misha Moroshko


2 Answers

Why aren't you just putting these together as functions, using an include, and calling them like you would in C++ or something? Global is bad.

like image 120
Incognito Avatar answered Sep 26 '26 18:09

Incognito


One solution (if imperfect) is to use file_get_contents() with a URL.

So, something like:

$data = file_get_contents('http://domain.com/a.php?this=that&that=this');
$json = json_decode($data);
like image 23
JKS Avatar answered Sep 26 '26 19:09

JKS