Jump to content

Can you use GET with Include files


galvin

Recommended Posts

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?)

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.