Jump to content

Recommended Posts

Hello, I am trying to include a file in a lot of my pages, but I am running into some problems.  I put an echo statement in the included file and that's showing up fine, but none of the variables are making the transition. Can someone enlighten me? I have no clue what could be going wrong.

 

Link to comment
https://forums.phpfreaks.com/topic/47627-solved-trouble-including-files/
Share on other sites

Yeah, sorry. 

Here's the code in the file that needs the include statement

<?php
require'http://www.shopjandl.com/includes/const_phrases.php';
?>
.
.
.
.
.
.
<?php echo POWER_WHEELS_INFO; ?>

 

and here's what I have in the included file:

<?php
define("POWER_WHEELS_INFO","Power Wheels Parts at ShopJandL.com is simple:<br><br>provide your model number from the list below to ensure correct Items are shipped.");

echo"the include worked!";
?>

 

I'm thinking this could be a problem with my php configuration?? I don't see how I could have a scope issue.

couldn't get that to work either... This is driving me nuts, because I can't see anywhere why this wouldn't work. It will work if I define the constant in the page itself, but not when I define it in an included file (which is obviously being included). Has anyone else had the same problem? Could I be overlooking something? In every example I've read there have been no indications that I would run into a problem like this.  :-\

Guest prozente

You are including the output of the PHP script and not the php script itself, this is because of how you included the file

 

Your code:

require'http://www.shopjandl.com/includes/const_phrases.php';

 

 

Say for example that file contained:

<?php  echo 'foo bar'; ?>

 

It would only include foo bar

 

because it would of already been processed by PHP.

 

Include the file locally and not over http

Okay, I just copied and pasted your code into test files and this is what I found:

 

If I used the FULL url path to the include file (i.e. http://....) the defined value was NOT present in the calling page.

 

If I used a relative path to the include file, the defined value was available.

 

Are you sure you tried MadTechie's second suggestion? Or you could change your server settings to include files using the full url:

 

allow_url_include

allow_url_fopen

 

I can't take credit for that last. Saw it mentioned in a post today: http://www.phpfreaks.com/forums/index.php/topic,136668.msg577758.html#msg577758

It has nothing to do with allow_url_fopen or allow_url_include.  PHP was intended to run on the server.  If you try to access a file over an HTTP connection, PHP will have already parsed it.  Personally, I wouldn't want people to be able to include my unparsed, full-code scripts over HTTP.

wow, thanks for all the replies. I was able to get it fixed using Mad Techie's advice. It turns out the reason using the local path didn't work was because I was using it with the defined() function in it. I didn't think to try it without it... But that was definitely the problem. Why would it make a difference though? I figured they were both (local and http) pointing to the same file and the server should be smart enough to recognize what my root is. I guess not. Anyway, problem solved and thanks again for the help.  ;)

Servers rule (simple terms)

if i connecting via (whatever):// then i am connecting to the outside world (well kinda) this will connect out then loop back either way the server see it as outside so for secuirty reasons its a no no (unless you override via php.ini)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.