Add GET or POST parameters on include files in PHP

PHP

Read {count} times since 2020

If you want to add GET parameters or POST parameters to files loading using include function in PHP then you should know the following:

It’s not possible. But it is in a different way.

If you are adding GET parameters to file name like the following, then it won’t work:

The above code won’t load the file, because PHP Include function only looks for files, it won’t send any parameters. It will search for file.php?user=subin in the directory for the case above. You can make it work in a different way.

We use $_GET and $_POST to get the parameters sent for each type. You should know that these variables are Arrays and not Strings. So you can just add a key and value to the array.

So to add the key and value just use the following code along with the include function :

$_GET[‘user’]="Subin";
include(‘file.php’);
?>

The above code works with the same as $_POST. When the file.php is loaded you will get the parameters using $_GET or $_POST.