I have a php script http://example.com/myapp/myscript.php running on an Apache server. I call this URL from a mobile app, the script does its logic, then set HTTP headers and body with data as a JSON string ( that the mobile app later parses and handles ).
Now I would like to have an URL http://example/myapp/mypage.php that would retrieve the data returned by myscript.php, lay it out with html and serve the page.
I achieve the result by first serving the page empty, myscript.php is then called via Ajax and the layout is done client-side with the Ajax response, but I wonder if it is possible to do this in only one http request :
1/ call mypage.php that would call and execute myscript.php on the server side
2/ retrieve the JSON data in mypage.php, parse it and lay it out on the server side
3/ serve the page
PHP include does not work, as it would just include the code, without executing it first.
Thank you.
Maybe I’m missing the question, but why can’t you just require() the .php file you need, then call a function in it?