JJBlaha Posted March 1, 2007 Share Posted March 1, 2007 The problem is this. index.php is this <? include('main/index.php'); ?> main/index.php is this $content = $_GET['content']; echo "con is $content"; when i put in index.php?content=blahblah It echos 'con is', but if i change index.php to what main/index.php is, it con is blahblah. Anyone know why? Quote Link to comment https://forums.phpfreaks.com/topic/40720-get-variables-not-working-when-i-include-the-file/ Share on other sites More sharing options...
monk.e.boy Posted March 1, 2007 Share Posted March 1, 2007 This should work. monk.e.boy Quote Link to comment https://forums.phpfreaks.com/topic/40720-get-variables-not-working-when-i-include-the-file/#findComment-197115 Share on other sites More sharing options...
monk.e.boy Posted March 1, 2007 Share Posted March 1, 2007 Actually, try putting: print_r( $_GET ); in both files. monk.e.boy Quote Link to comment https://forums.phpfreaks.com/topic/40720-get-variables-not-working-when-i-include-the-file/#findComment-197116 Share on other sites More sharing options...
JJBlaha Posted March 1, 2007 Author Share Posted March 1, 2007 If i put it in main/index.php (the inlcuded one) I get Array ( ) 1 If i put it in index.php i get Array ( [content] => blahblah ) Quote Link to comment https://forums.phpfreaks.com/topic/40720-get-variables-not-working-when-i-include-the-file/#findComment-197123 Share on other sites More sharing options...
JJBlaha Posted March 1, 2007 Author Share Posted March 1, 2007 Possibly important piece of information: index.php is on a subdomain, like sub.domain.com, and is including the file www.domain.com/main/index.php I know the file is being included, because it outputs con is, but the variable is not working. Quote Link to comment https://forums.phpfreaks.com/topic/40720-get-variables-not-working-when-i-include-the-file/#findComment-197139 Share on other sites More sharing options...
Snooble Posted March 1, 2007 Share Posted March 1, 2007 have you tried outputting the variable straight from the URL. Is it actually posting? Just examine it i'm sure it'll be something simple. If you see some contents of the included file then it doesn't matter about being on a subdomain etc. Just look at the get method and make sure it's back to itself. <?php ECHO "$_GET['content']"; ?> Snooble Quote Link to comment https://forums.phpfreaks.com/topic/40720-get-variables-not-working-when-i-include-the-file/#findComment-197145 Share on other sites More sharing options...
JJBlaha Posted March 1, 2007 Author Share Posted March 1, 2007 If i put <?php echo $_GET['content']; ?> in the included file nothing shows, but if it put it in the original file it does show. It seems it matters that it is included for some reason. Quote Link to comment https://forums.phpfreaks.com/topic/40720-get-variables-not-working-when-i-include-the-file/#findComment-197152 Share on other sites More sharing options...
JJBlaha Posted March 1, 2007 Author Share Posted March 1, 2007 The get variables are undefined if they are in the included file on the main site (www.domain.com/main/index.php) but they work perfectly on the regular subdomain file (sub.domain.com/index.php). The code used in every case was the exact same, the only difference is that it is either included or is not. Quote Link to comment https://forums.phpfreaks.com/topic/40720-get-variables-not-working-when-i-include-the-file/#findComment-197176 Share on other sites More sharing options...
genericnumber1 Posted March 1, 2007 Share Posted March 1, 2007 so you're saying the included file doesn't get the $_GET variables? something like this?... page1.php <?php include('page2.php'); ?> page2.php <?php echo $_GET['test']; ?> a call to page1.php?test=test doesn't do anything? sounds like a server problem.... Quote Link to comment https://forums.phpfreaks.com/topic/40720-get-variables-not-working-when-i-include-the-file/#findComment-197180 Share on other sites More sharing options...
JJBlaha Posted March 1, 2007 Author Share Posted March 1, 2007 page1.php <?php include('page2.php'); ?> page2.php <?php echo "Test is "; echo $_GET['test']; ?> and a call to page1.php?test=test outputs 'Test is' Quote Link to comment https://forums.phpfreaks.com/topic/40720-get-variables-not-working-when-i-include-the-file/#findComment-197191 Share on other sites More sharing options...
genericnumber1 Posted March 1, 2007 Share Posted March 1, 2007 realllly weird problem, what version of php are you using? Really starting to sound like a server problem. Quote Link to comment https://forums.phpfreaks.com/topic/40720-get-variables-not-working-when-i-include-the-file/#findComment-197213 Share on other sites More sharing options...
JJBlaha Posted March 1, 2007 Author Share Posted March 1, 2007 Using PHP Version 4.4.4 Quote Link to comment https://forums.phpfreaks.com/topic/40720-get-variables-not-working-when-i-include-the-file/#findComment-197244 Share on other sites More sharing options...
craygo Posted March 1, 2007 Share Posted March 1, 2007 Your original code works fine for me. try using $_REQUEST instead of $_GET. Ray Quote Link to comment https://forums.phpfreaks.com/topic/40720-get-variables-not-working-when-i-include-the-file/#findComment-197248 Share on other sites More sharing options...
JJBlaha Posted March 1, 2007 Author Share Posted March 1, 2007 Sorry, I made a mistake in what I was saying earlier, the correct representation of my problem is as follows. sub.domain.com/page1.php <?php include('http://www.domain.com/main/page2.php'); ?> www.domain.com/main/page2.php <?php echo "Test is "; echo $_GET['test']; ?> http://sub.domain.com/page1.php?test=test returns Test is Quote Link to comment https://forums.phpfreaks.com/topic/40720-get-variables-not-working-when-i-include-the-file/#findComment-197292 Share on other sites More sharing options...
JJBlaha Posted March 1, 2007 Author Share Posted March 1, 2007 And if i change page1.php to sub.domain.com/page1.php <?php echo "Test is "; echo $_GET['test']; ?> http://sub.domain.com/page1.php?test=test returns Test is test Quote Link to comment https://forums.phpfreaks.com/topic/40720-get-variables-not-working-when-i-include-the-file/#findComment-197333 Share on other sites More sharing options...
genericnumber1 Posted March 2, 2007 Share Posted March 2, 2007 you cant include pages via URLs like that.... do local file paths, not URLs Quote Link to comment https://forums.phpfreaks.com/topic/40720-get-variables-not-working-when-i-include-the-file/#findComment-197518 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.