galvin Posted November 18, 2011 Share Posted November 18, 2011 Can you include a file and append info to be grabbed by using GET? For example, can you have an include file like this... include('file.php?id=1'); And then in the file "file.php" I would use $_GET['id'] to do other things in the code. I tried it and it's not working. I'm getting this error... "Warning: include(file.php?id=1) [function.include]: failed to open stream: No such file or directory in..." Just want to find out if this should be doable before I continue testing why it's not working for me. If it should work, should I be using something other than include maybe? (like require or require_once?) Quote Link to comment https://forums.phpfreaks.com/topic/251398-can-you-use-get-with-include-files/ Share on other sites More sharing options...
KevinM1 Posted November 18, 2011 Share Posted November 18, 2011 Like the error says, no, it doesn't make sense to pass a query string to an include function. It's looking for a file at the path sent into the function. Unless you have a file named 'file.php?id=1', you're not going to get a match. Really, the error message is pretty explanatory about what include is trying to do and why it's failing. And, no switching to one of the others, like require, wouldn't work either as they all work the same way. What you can do is simply have file.php include the file you want. Your included code will be pasted, line by line, in memory at that spot, so you should still have access to $_GET without any extra work. Quote Link to comment https://forums.phpfreaks.com/topic/251398-can-you-use-get-with-include-files/#findComment-1289399 Share on other sites More sharing options...
galvin Posted November 18, 2011 Author Share Posted November 18, 2011 ok, thanks very much for the info!! Quote Link to comment https://forums.phpfreaks.com/topic/251398-can-you-use-get-with-include-files/#findComment-1289400 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.