Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - include a php file and also send query parameters

I have to show a page from my php script based on certain conditions. I have an if condition and am doing an "include" if the condition is satisfied.

if(condition here){   include "myFile.php?id='$someVar'"; } 

Now the problem is the server has a file "myFile.php" but I want to make a call to this file with an argument (id) and the value of "id" will change with each call.

Can someone please tell me how to achieve this? Thanks.

like image 408
lostInTransit Avatar asked Aug 05 '09 09:08

lostInTransit


People also ask

What is the correct way to include a file text PHP in PHP code?

The include (or require ) statement takes all the text/code/markup that exists in the specified file and copies it into the file that uses the include statement. Including files is very useful when you want to include the same PHP, HTML, or text on multiple pages of a website.

Can we include PHP file using Combine () function?

Instead of writing all our code in a single file, PHP allows us to INCLUDE other files, so they function as part of the current page, while keeping them separate. This is very useful for organization and not repeating code for things such as footers and navigation.

How do I call a PHP function from another file?

You just need to include the other file: include('function. php'); index.


1 Answers

Imagine the include as what it is: A copy & paste of the contents of the included PHP file which will then be interpreted. There is no scope change at all, so you can still access $someVar in the included file directly (even though you might consider a class based structure where you pass $someVar as a parameter or refer to a few global variables).

like image 122
Daff Avatar answered Oct 13 '22 12:10

Daff