Search code examples
phpdata-transfer

How to send data from one php file to another php file?


I'm currently using a JQuery ajax function to post data into a PHP file. That PHP code loads an XML file located outside the server root directory, then compare strings before echoing back to my js/html.

But I need to post the data retrieved from that XML file to a second PHP file and echo the results from that last file to my js.

JS

function dataSend(info1, info2){
var myData = {
    info1 : info1,
    info2 : info2
}
$.ajax({
    type: "POST",
    url: "../php/file1.php",
    data: myData,
    success: function(response){
        alert(response);
    }
});
}

FILE1.PHP

Here I obtain a string ($token) from a node in the XML file based on the data I sent from the JQuery POST function. Now I need to send this string to another PHP file.

FILE2.PHP

Here I need to get that $token and send a new variable ($newtoken) back to file1.php

BACK TO FILE1.PHP

Finally, how do I get $newtoken from file2.php?

I'm sure this is quite simple. Thanks!


Solution

  • on file1.php put:

    require_once "file2.php";