How to call a php script from another php script?

I have a PHP script, say a.phpthat 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.phpand pass some data to it. I expect a.phpto complete the task just as if it had been called from JS.

I do not want to do include('a.php');due to a possible collision of variable names.

How can i do this?

+3
source share
5 answers

Why don't you just combine them as functions using include and call them the same way as in C ++ or something like that? Globally bad.

+3

( ) - file_get_contents() URL-.

, - :

$data = file_get_contents('http://domain.com/a.php?this=that&that=this');
$json = json_decode($data);
+2

HTTP curl file_get_contents. , . , , .

+1

PHP 5.3, Namespaces, .

- , , . .

+1

One way is to enter a server request from b.phpwith the URL for a.php, which is commonly used by the client.

0
source

Source: https://habr.com/ru/post/1768525/


All Articles