Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - include file with POST data

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?

like image 209
Jason Lipo Avatar asked Dec 20 '22 20:12

Jason Lipo


2 Answers

The $_POST superglobal array is writeable in a PHP script, so:

<?php

$_POST["key"] = "value";
include("myfile.php");

?>
like image 63
mcserep Avatar answered Dec 24 '22 00:12

mcserep


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.

like image 23
floriank Avatar answered Dec 24 '22 01:12

floriank