0

I am having an odd problem that continues to baffle me. I appreciate your advice....

In a PHP 5.3 script I am including another PHP script using the following code;

include 'moninit.php?id=1234';  // initialize array variables

moninit.php is stored as C:\xampp\htdocs\CarmelServices\moninit.php

In php.ini the include path is:

include_path = "C:\xampp\htdocs\CarmelServices"

So, the include should execute moninit.php but I get the following error returns;

Warning: include(moninit.php?id=1234) [function.include]: failed to open stream: No error in C:\xampp\htdocs\CarmelServices\SensorW.php on line 48

Warning: include() [function.include]: Failed opening 'moninit.php?id=1234' for inclusion (include_path='C:\xampp\htdocs\CarmelServices') in C:\xampp\htdocs\CarmelServices\SensorW.php on line 48

If I execute moninit.php directly using a browser, it works fine. So, somehow the include cant seem to find moninit. SensorW is also in the same folder as moninit.

Very odd, at least to me. Thanks!

3 Answers 3

1

include does not execute a PHP script; it only inserts the contents of the file into the currently-running script.

In your example, you are telling the PHP interpreter to find and open a file named 'moninit.php?id=1234' which does not exist. You may wish to include 'monit.php' itself or find another way (such as cURL) to execute the script and retrieve the response.

Sign up to request clarification or add additional context in comments.

1 Comment

George, Brilliant! Makes sense. I will reconfigure the id= portion. Thank you very much. Al
1

You cannot pass array variables with it, it's included directly in your script and will inherit any variables in the available scope. So you can assign to an array and use that instead.

$data = array('id' => '1234');
include 'moninit.php'; // In moninit.php, use $data instead

If you're just routing the parameters passed, don't worry - they already work.

Comments

0

@GeorgeCummins' answer explains how include() works. Also, you can only pass it the name of the file. You can't pass it variables like you're doing. It's a file name, not a URL.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.