lifeson2112 Posted April 18, 2007 Share Posted April 18, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/47627-solved-trouble-including-files/ Share on other sites More sharing options...
Psycho Posted April 18, 2007 Share Posted April 18, 2007 Some code to view would be nice. Are you including the file using a function? Could be an issue of variable scope. Quote Link to comment https://forums.phpfreaks.com/topic/47627-solved-trouble-including-files/#findComment-232558 Share on other sites More sharing options...
lifeson2112 Posted April 18, 2007 Author Share Posted April 18, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/47627-solved-trouble-including-files/#findComment-232563 Share on other sites More sharing options...
MadTechie Posted April 18, 2007 Share Posted April 18, 2007 try echo defined('POWER_WHEELS_INFO'); also require 'includes/const_phrases.php'; Quote Link to comment https://forums.phpfreaks.com/topic/47627-solved-trouble-including-files/#findComment-232569 Share on other sites More sharing options...
lifeson2112 Posted April 18, 2007 Author Share Posted April 18, 2007 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. :-\ Quote Link to comment https://forums.phpfreaks.com/topic/47627-solved-trouble-including-files/#findComment-232643 Share on other sites More sharing options...
lifeson2112 Posted April 18, 2007 Author Share Posted April 18, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/47627-solved-trouble-including-files/#findComment-232671 Share on other sites More sharing options...
Guest prozente Posted April 18, 2007 Share Posted April 18, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/47627-solved-trouble-including-files/#findComment-232707 Share on other sites More sharing options...
Psycho Posted April 19, 2007 Share Posted April 19, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/47627-solved-trouble-including-files/#findComment-232755 Share on other sites More sharing options...
Glyde Posted April 19, 2007 Share Posted April 19, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/47627-solved-trouble-including-files/#findComment-232763 Share on other sites More sharing options...
lifeson2112 Posted April 19, 2007 Author Share Posted April 19, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/47627-solved-trouble-including-files/#findComment-232773 Share on other sites More sharing options...
MadTechie Posted April 19, 2007 Share Posted April 19, 2007 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) Quote Link to comment https://forums.phpfreaks.com/topic/47627-solved-trouble-including-files/#findComment-232781 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.