If I get you right, you want to transfer the variable from one php file to another through a message. There are several ways to do this.
1. With an HTML form
<form action="target.php" method="post"> <input type="text" name="key" value="foo" /> <input type="submit" value="submit" /> </form>
if you press the submit button, $_POST['key'] in target.php will contain 'foo' .
2. Directly from PHP
$context = stream_context_create(array( 'http' => array( 'method' => 'POST', 'header' => "Content-type: text/html\r\n", 'content' => http_build_query(array('key' => 'foo')) ), )); $return = file_get_contents('target.php', false, $context);
Same as in 1., and $return will contain all the output generated by target.php .
3. Via AJAX (jQuery (JavaScript))
<script> $.post('target.php', {key: 'foo'}, function(data) { alert(data); }); </script>
Same as 2., but now data contains output from target.php .
source share