williamZanelli Posted June 11, 2009 Share Posted June 11, 2009 Hi guys, I'm grappling with a small issue I have. I need to call a local PHP file, from inside another PHP file.. Some for example, I would like to call the file modeule.php, using the 2 variables.. from inside max.php. max.php <?php //required to call the module.php /module.php?var1=xyz&var2=abc ?> What the best way of achieveing this? Thanks Will Quote Link to comment https://forums.phpfreaks.com/topic/161889-calling-a-local-php-file/ Share on other sites More sharing options...
laPistola Posted June 11, 2009 Share Posted June 11, 2009 with out knowing what the vars will achive i would say either include(modeule.php) then make the vars do what ever or maybe use the cURL lib if you need it to return a string or something. Quote Link to comment https://forums.phpfreaks.com/topic/161889-calling-a-local-php-file/#findComment-854138 Share on other sites More sharing options...
williamZanelli Posted June 12, 2009 Author Share Posted June 12, 2009 Right.. But the prob I have is, I cant modify module.php... which takes it variable via $_GET, So how do I pass variables to the include(module.php) ?? Do you have any examples of cURL...? Thanks Will Quote Link to comment https://forums.phpfreaks.com/topic/161889-calling-a-local-php-file/#findComment-854164 Share on other sites More sharing options...
laPistola Posted June 12, 2009 Share Posted June 12, 2009 You cant pass vars via include() as for as i know the cURL im working on at min is for a working google map geo query so i have just copied and pasted but changed the URL <?php $url = $_SERVER['PHP_SELF'] . "modeule.php?var1=xyz&var2=abc"; // make this the direct path to the file $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER,0); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); ?> This will return a string in to the $data var but you will need to set up your modeule.php file to return the data. Quote Link to comment https://forums.phpfreaks.com/topic/161889-calling-a-local-php-file/#findComment-854174 Share on other sites More sharing options...
haku Posted June 12, 2009 Share Posted June 12, 2009 You don't need to pass the variables to the included file - once you include it, all variables in the calling file (and environment) are available to it. Quote Link to comment https://forums.phpfreaks.com/topic/161889-calling-a-local-php-file/#findComment-854200 Share on other sites More sharing options...
williamZanelli Posted June 12, 2009 Author Share Posted June 12, 2009 Right, Thanks for the info guys.. Which approach is the best then? I want something efficient and robust. Thanks for your thoughts thus far, you have been wonderful. Quote Link to comment https://forums.phpfreaks.com/topic/161889-calling-a-local-php-file/#findComment-854356 Share on other sites More sharing options...
Daniel0 Posted June 12, 2009 Share Posted June 12, 2009 Just include or require the file. The variables that are accessible the place you include from will be available in the included file as well, as haku said. Quote Link to comment https://forums.phpfreaks.com/topic/161889-calling-a-local-php-file/#findComment-854357 Share on other sites More sharing options...
laPistola Posted June 15, 2009 Share Posted June 15, 2009 The include/require is by far the best way Quote Link to comment https://forums.phpfreaks.com/topic/161889-calling-a-local-php-file/#findComment-856591 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.