piscatorhominum Posted July 1, 2010 Share Posted July 1, 2010 my "$_get" function is not retrieving the "id" variable from the URL (".../index.php?id=1") I have no clue why it isn't "getting" the variable. I don't get any error messages from the server and I've tried to echo the variable and it just won't read "id" from the URL <?php $article = $_GET['id']; if ($article == 1) { include 'article1.php'; } elseif ($article == 2) { include 'article2.php'; } elseif ($article == 3) { include 'article3.php'; } elseif ($article == 4) { include 'article4.php'; } else { include 'no_article.php'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/206451-_get-is-not-retrieving-my-variable-from-the-url/ Share on other sites More sharing options...
kenrbnsn Posted July 1, 2010 Share Posted July 1, 2010 Put <?php echo '<pre>' . print_r($_GET,true) . '</pre>'; ?> at the start of your script and see what prints out. Ken Quote Link to comment https://forums.phpfreaks.com/topic/206451-_get-is-not-retrieving-my-variable-from-the-url/#findComment-1079973 Share on other sites More sharing options...
bspace Posted July 2, 2010 Share Posted July 2, 2010 or somewhat more simply var_dump($_GET); Quote Link to comment https://forums.phpfreaks.com/topic/206451-_get-is-not-retrieving-my-variable-from-the-url/#findComment-1080047 Share on other sites More sharing options...
kenrbnsn Posted July 2, 2010 Share Posted July 2, 2010 When it's done my way, the dump is formatted in a much more readable way. Try it on an array and see which produces a more readable display. Ken Quote Link to comment https://forums.phpfreaks.com/topic/206451-_get-is-not-retrieving-my-variable-from-the-url/#findComment-1080093 Share on other sites More sharing options...
djfox Posted July 2, 2010 Share Posted July 2, 2010 Are you testing this script off your harddrive or do you have it uploaded onto a server? Quote Link to comment https://forums.phpfreaks.com/topic/206451-_get-is-not-retrieving-my-variable-from-the-url/#findComment-1080096 Share on other sites More sharing options...
piscatorhominum Posted July 2, 2010 Author Share Posted July 2, 2010 djfox: It's on my server kenrbnsn: I uploaded the code you gave me and then visited the page THAT INCLUDES THE SCRIPT and it had empty parentheses. I put those words in caps because the script is included on my website, not in the "index.php" file itself. I think this has something to do with it because when i point my browser to the actual script with the "id" variable in the URL it prints: Array ( [id] => 7 ) Quote Link to comment https://forums.phpfreaks.com/topic/206451-_get-is-not-retrieving-my-variable-from-the-url/#findComment-1080325 Share on other sites More sharing options...
PFMaBiSmAd Posted July 2, 2010 Share Posted July 2, 2010 script is included on my website Maybe if you show your actual full code involved in the problem someone could directly solve this. xxxxx out any information you don't want to post, such as your domain name, but don't change any of the syntax (such as if you are using a URL to include the file http://xxxxx.com/file.php or using a file system path.) Quote Link to comment https://forums.phpfreaks.com/topic/206451-_get-is-not-retrieving-my-variable-from-the-url/#findComment-1080330 Share on other sites More sharing options...
piscatorhominum Posted July 2, 2010 Author Share Posted July 2, 2010 You're right. I might as well. But I feel like it would be unnecessary since my "index.php" only contains: <?php include 'http://xxx/article_fetch.php';?> and I already posted the "article_fetch.php" script. Quote Link to comment https://forums.phpfreaks.com/topic/206451-_get-is-not-retrieving-my-variable-from-the-url/#findComment-1080386 Share on other sites More sharing options...
rookwood Posted July 2, 2010 Share Posted July 2, 2010 lol @PFMaBiSmAd have you seen what that links to! Quote Link to comment https://forums.phpfreaks.com/topic/206451-_get-is-not-retrieving-my-variable-from-the-url/#findComment-1080391 Share on other sites More sharing options...
kenrbnsn Posted July 2, 2010 Share Posted July 2, 2010 Don't use a URL in the include statement. Use a normal file name. Ken Quote Link to comment https://forums.phpfreaks.com/topic/206451-_get-is-not-retrieving-my-variable-from-the-url/#findComment-1080403 Share on other sites More sharing options...
PFMaBiSmAd Posted July 2, 2010 Share Posted July 2, 2010 I knew using a URL was probably it. When you post part of your code out of context of how it is actually being used and you tell us that 'this is my code and it is not working', but in reality that is not all your actual code that is involved in the problem, it takes a really long time to help you, in this case ~20hours. When you use a URL in an include, it causes your web server to make a http request back to your web server. This invokes a separate instance/child process of your web server/php to parse the requested file. This causes several things to happen - 1) It takes a minimum of 100 times longer than if you used a directly file system path, 2) The included file does not inherit the variable scope of the main file (which is why you are getting the symptoms that you are), 3) You only get back the content that is output by that file, you don't get the php code and data from that file incorporated into the main file, and 4) The settings that allow this might not be enabled on any particular server configuration, so you might find your include statement not working at all (and not just the variables) if you move to a different server or someone updates/alters the configuration of your existing server. Quote Link to comment https://forums.phpfreaks.com/topic/206451-_get-is-not-retrieving-my-variable-from-the-url/#findComment-1080445 Share on other sites More sharing options...
piscatorhominum Posted July 3, 2010 Author Share Posted July 3, 2010 That solved the problem. Thank you guys for the help. It is much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/206451-_get-is-not-retrieving-my-variable-from-the-url/#findComment-1080776 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.