I have a PHP file which takes POST data. I run this file currently through AJAX in jQuery:
$.post("myfile.php", { key: value });
I want to run this same file but within another PHP script. This is what I want to achieve:
<?php
include("myfile.php", array("key" => "value") );
?>
I know that the include
function doesn't take other parameters, so is there a way to include another PHP file with POST variables?
The $_POST
superglobal array is writeable in a PHP script, so:
<?php
$_POST["key"] = "value";
include("myfile.php");
?>
Any post data should be accessible everywhere in your scripts using $_POST.
So just use the post data in your myfile.php by accessing it through $_POST['key'] to get your value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With