-3

I am trying to send a variable "q" to a search page through url. but i get the error saying

Fatal error: require(): Failed opening required 'theme/_modules/contact/search.php?q={echo $q;}' (include_path='.:/usr/lib/php:/usr/local/lib/php')

here is my code

    if(isset($_POST['q'])){
    $q= $_POST['q'];
    }

    require 'theme/header.php';
    require 'theme/_modules/contact/search.php?q={echo $q;}';
    require 'theme/footer.php';

can any one tell me the reason and a way to over come this problem.. thank you..

after doing this..

require 'theme/header.php';
//require 'theme/_modules/contact/search.php?q={echo $q;}';
require "theme/_modules/contact/search.php?q=$q";
require 'theme/footer.php';

i get the error

 Warning: require(theme/_modules/contact/search.php?q=saman): failed to open stream: No such file or directory in /home/dr7bf45v/public_html/search.php on line 17
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Sathya Baman
  • 3,424
  • 7
  • 44
  • 77

2 Answers2

5

Use this:

require 'theme/_modules/contact/search.php?q='.$q;

When you are using this...

require 'theme/_modules/contact/search.php?q={echo $q;}';

PHP is interpreting {echo $q;} literally, because it is encased in single quotes. Usually PHP will interpret {echo $q;} as you want in double quotes, but to be safe, use the . to tack something on to the end of a string. If you wanted to encase $q in double quotes without having to use the ., do it like this...

require "theme/_modules/contact/search.php?q=$q";
Locke
  • 661
  • 1
  • 6
  • 17
  • Thank you. but i get the error.. `Warning: require(theme/_modules/contact/search.php?q=saman): failed to open stream: No such file or directory in /home/dr7bf45v/public_html/search.php on line 17` But am sure i have the file search.php in theme/_modules/contact/ – Sathya Baman Jun 26 '14 at 04:50
  • Update your post to hold the current code. – Locke Jun 26 '14 at 04:50
1

I think that you are trying to go over a wrong way.

You are trying to accomplish remote including. (1. you must allow it: including a remote file in PHP. 2. your link should looks like url).

Now you are trying to require theme/_modules/contact/search.php?q=saman it's mean that your script looking for file with name search.php?q=saman. Do you have that file? No. Only search.php.

But, I think, you are trying to pass variable to the file scope. There a better way to this. Just require it without extra params.

P.S. but if search.php receives value from GET and you need that result you could use curl because remote including is dangerous.

Community
  • 1
  • 1
sectus
  • 15,605
  • 5
  • 55
  • 97