I'm trying to read the a variable/value that was passed in the URL.
as an experiment, I started with 2 simple files.
test.php
<?php
//option1
//include "http://myhost.com/test2.php?tempvar=testonly";
//option2
//$tempvar = "testonly";
//include "http://myhost.com/test2.php";
//option3
$tempvar = "testonly";
include ("test2.php)";
?>
test2.php
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
console.log(getURLParameter("tempvar"));
$("#test").html(getURLParameter("tempvar"));
function getURLParameter(name) {
return (decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search.toLowerCase())||[,""])[1].replace(/\+/g, '%20'))).toUpperCase()||"";
}
});
</script>
<div id="test"><?php echo tempvar; ?></div>
some observations:
If I call http://myhost.com/test.html?tempvar=testonly from my browser tab, it works fine (i.e. testonly is displayed on the page)
if I call http://myhost.com/test.php from my browser, no "testonly" is displayed on my page. So it seems my getURLParameter javascript function is not finding the tempvar that was passed via include. According to the include manual (example 3), this should work.
Only option3 works in my test.php BUT in my situation, this is useless to me as test2.php can be in another host. and it's possible test2.php can be replaced by another programming language like java (.jsp) or coldfusion or even just plain HTML and DB communication is handled through AJAX calls.
According to phpinfo, the server is using PHP 5.1.6. maybe I need a specific PHP extension to make it work?
Thanks a lot