Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - include() file not working when variables are put in url?

In PHP I've build a webpage that uses include() for loading parts of the website. However, I now ran into something like a problem: When I use an url like: data-openov-storingen.php?type=actueel It gives me this error:

Warning: include(data-storingen.php?type=actueel): failed to open stream: No such file or directory in blablabla

Is it even possible to pass get variables in an include() url?

like image 954
laarsk Avatar asked Nov 30 '22 07:11

laarsk


2 Answers

include in this way doesn't fetch a URL, it fetches a file from the filesystem, so there's no such thing as a query string.

You can do this, though:

$_GET['type'] = 'actueel';
include('data-storingen.php');
like image 197
ceejayoz Avatar answered Dec 06 '22 00:12

ceejayoz


The include() function does not access the file via HTTP, it accesses the file through the OS's own file system. So GET variables are not counted. (as they are not part of the file name).

In layman's terms, the point of include is to "copy/paste" all the contents on one file to another on the file, so that you don't have one gigantic file, but a few smaller, more maintainable ones.

like image 24
Madara's Ghost Avatar answered Dec 06 '22 00:12

Madara's Ghost