Jump to content

[SOLVED] Echo inside include?


mnybud

Recommended Posts

Newbie questions time :)

 

I am trying to accomplish the following:

 

I have a url formated like this:

http://www.domain.com/?word_I_want=thisword

 

I can echo "thisword" fine on my page with

 <?PHP  echo $_REQUEST['word_I_want']; ?>

 

But I also need to include it within this after ?query=

<?PHP include("parser.php?query=word_I_want") ?>

 

I know this should be simple but I have tried several variations of what I thought might work and keep getting syntax errors. Can anyone help me out please?

Link to comment
https://forums.phpfreaks.com/topic/138540-solved-echo-inside-include/
Share on other sites

All you need to do is retrieve the variable THEN include the file and due to the scope of the variable it should be accessible in the included file.

 

$variable = $_GET['word_I_want'];

include("page.php");

 

page.php:

echo $variable;

 

Also, use $_GET for retrieving variables from the URL, not $_REQUEST because that also stores the $_POST variables. You're better off specifying the one you want.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.