Forum Moderators: coopster
$category = 'Foo';
$subcategory = 'Bar';
include('http://www.example.com/example.php'); On that example.php page, there is a query to a MySQL database, attempting to pull all the data where category = $category and subcategory = $subcategory, but it's not working -- looks like the external include doesn't see the variables that were set on the original page? Is there another or better way to achieve this? I actually have several pages, each with a different set of variables that I'd like to use to call up this one query.
One alternative I've tried is to just set the variables in the url of the include, like this:
include('http://www.example.com/example.php?category=Foo&subcategory=Bar'); There's no problem with the page reading the external include -- I echoed the query just to be sure allow_external_includes was on, and echoing the query showed that it just wasn't seeing the variables.
Curl [google.com] is a more proper solution, but regardless, the remote script won't automatically have access to the local variables. You'll have to set the variables in the url, as you mentioned. To avoid problems with spaces, you can urlencode() the variables first.
Yes, it should work but it would big a risk, especially since db credentials may be revealed.
The script doesn't have access to the local variables because you are not getting the PHP code included into your script, but rather the output from the PHP script on the other server. As penders hinted to it is being parsed on the other server first before yours. If you want to include the PHP code into your script then you are going to need to find another way.