Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php parse variables

Status
Not open for further replies.

mwpclark

Programmer
Mar 14, 2005
59
US
Hi

I use php includes all the time, and I'm looking for a way to do something that **may** not be possible.

Often I include a file using the server path:
Code:
include ('path/file.php');
If I have identified variables in the parent script, they are passed to the included script, and the included script is treated as an add-on to the parent script.

However in other cases I need to include a url in order to pass variables to be parsed:
Code:
include ('[URL unfurl="true"]http://somedomain.com/file.php?var=x');[/URL]

I have very many of these running, and I want to speed up page loading times and minimize server load. Is there any way -- a flag, a function, a class -- to get php to parse these variables without the http call?

Thanks
Mike
 
that sounds like you have an architecture issue more than a php issue. using http:// protocol essentially means that you want to grab plain text. you cannot get executable php code from including via http (without subsequently exec'ing

you might try a straightforward exec or backtick call. you would need to set the necessary variables first. in your case you would explicitly set the $_GET super global. Messy, bad programming practice, but it can be done.

but i think you could probably get the same effect from manipulating the $_GET superglobal and simply including the file as php code.

if you need to capture the output as a string then you can use output control functions, but since you are using include(http:// ... at the moment, it seems that output control is not the aim here.
 
Thanks jpadie

I found the answer -- to set variables first then include with full path -- some includes seem to work using a relative path -- but not this one.

Cheers
Mike
 
that's what i said

get the same effect from manipulating the $_GET superglobal and simply including the file as php code

php does not need an absolute url but it does need to know where to find the file and a script with a relative path may not always itself be called from the same location. two ways around this: first is to set the include path in php.ini (or equivalent) and the second (which I use) is to have a file that is definitively called for every script that sets a definition equal to the path to the root of your site; then everywhere else in your code you can do
Code:
include BASE .'/path/to/script'

this makes the code very portable as you need only change one definition to make all the includes work
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top