ricmetal Posted March 20, 2014 Share Posted March 20, 2014 hi guys so im trying to access a variable from an included php file, included using a full address, with http://www... but its not working. i read up on php manual but i dont get the answers im using php 5.3 path is correct allow url is on included file is inclosed with php tags... could i get some help? here is the simple code i am using // included.php <?php $a = "data"; ?> // main.php <?php include "http://www.somedomain.com/included.php"; echo $a; // outputs nothing ?> what gives? gracias Quote Link to comment https://forums.phpfreaks.com/topic/287118-newbie-question-or-maybe-not/ Share on other sites More sharing options...
Ansego Posted March 20, 2014 Share Posted March 20, 2014 (edited) Make sure this is set allow_url_include in you php.ini file. Reference: http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-include Edited March 20, 2014 by Ansego Quote Link to comment https://forums.phpfreaks.com/topic/287118-newbie-question-or-maybe-not/#findComment-1473280 Share on other sites More sharing options...
Ch0cu3r Posted March 20, 2014 Share Posted March 20, 2014 The behaviour you have experience is correct. When including a file using a url, only the output from that file is returned, not the raw php source code. Quote Link to comment https://forums.phpfreaks.com/topic/287118-newbie-question-or-maybe-not/#findComment-1473283 Share on other sites More sharing options...
ricmetal Posted March 20, 2014 Author Share Posted March 20, 2014 The behaviour you have experience is correct. When including a file using a url, only the output from that file is returned, not the raw php source code. oh. didn't read that on the php manual website! thanks! Quote Link to comment https://forums.phpfreaks.com/topic/287118-newbie-question-or-maybe-not/#findComment-1473284 Share on other sites More sharing options...
ricmetal Posted March 20, 2014 Author Share Posted March 20, 2014 Make sure this is set allow_url_include in you php.ini file. Reference: http://www.php.net/manual/en/filesystem.configuration.php#ini.allow-url-include yep, allow_url_include is off. also didnt see that bit of info on php manual site. anyway, i dont wanna need to mess with ini settings for this one. ill have to go around using the full address. thanks! Quote Link to comment https://forums.phpfreaks.com/topic/287118-newbie-question-or-maybe-not/#findComment-1473287 Share on other sites More sharing options...
Ch0cu3r Posted March 20, 2014 Share Posted March 20, 2014 Why are you needing to use a url to include a file? What is it you are trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/287118-newbie-question-or-maybe-not/#findComment-1473288 Share on other sites More sharing options...
ricmetal Posted March 20, 2014 Author Share Posted March 20, 2014 (edited) i am trying to work with htaccess! trying to figure out how it works still - i thought i would need to use the full address but im more confused now that before lol i thought the 404 custom error page would keep the original url the user typed in (the failed url, hence the 4040 error) so the 404 error page would need to target elements scattered across the folder tree. thus the need for the include with full url. btw, regarding htaccess, does anybody know if it is at all possible to automatically make the folder in which the htaccess is, the root folder? i read alot of people using hardcoded url to set their base folders but i would like to have this automated if possible. Edited March 20, 2014 by ricmetal Quote Link to comment https://forums.phpfreaks.com/topic/287118-newbie-question-or-maybe-not/#findComment-1473349 Share on other sites More sharing options...
Ch0cu3r Posted March 20, 2014 Share Posted March 20, 2014 I think you are getting confused with how PHP and HTML works. PHP uses file paths when requiring files from the file system. Whereas HTML uses http requests (a url) to request for files from the server. PHP has nothing do with the .htaccess (unless you are using the php_flag or php_value directives to alter PHP's config). The .htaccess file is only invoked when responding to a http request. Quote Link to comment https://forums.phpfreaks.com/topic/287118-newbie-question-or-maybe-not/#findComment-1473359 Share on other sites More sharing options...
Solution ricmetal Posted March 20, 2014 Author Solution Share Posted March 20, 2014 (edited) i understand. my issue was that in thinking that the 404.php page would show up, in place of a nonexistent, typed-in url (by a user), and seeing that the 404.php file needs to include elements found across the folder tree, that i would need to target them using the full path. while this is correct, it is incorrect to think the nonexistent url would stay the same while the 404.php would be shown. i don't know why i was thinking that that is how it worked, but you see my logic in needing to use the full path, and why i brought htaccess into the picture. if a file is not found, show the custom 404.php error page. from the 404.php page, include another file to use elements found in different areas of the tree. and to target them from different locations where the 404.php would be shown, i'd need the full url. hehe so, it turns out that the htaccess redirect when a page is not found actually redirects the url to the custom 404.php page instead of 'moving' the 404 file to the current location the user is. HENCE, liking to automatically set the root of the website to where the htaccess file is. Seeing htaccess is complicated as chinese algebra and a little bit of Dead Space moon talk, i decided to hardcode the website's root folder in the htaccess file and remember that the custom 404.php error page does not move places in the tree folder, hence, not needing to use ful url's to include other folders from the server tree, as well. and that is a wrap. this is what you get when you start building something in which you are a tad bit buried into too much of what you don't know, backed up with alot of what you'd like that and taking long breaks while doing so! cheers! Edited March 20, 2014 by ricmetal Quote Link to comment https://forums.phpfreaks.com/topic/287118-newbie-question-or-maybe-not/#findComment-1473363 Share on other sites More sharing options...
Ch0cu3r Posted March 20, 2014 Share Posted March 20, 2014 If you are passing ErrorDocument an absolute url to 404.php, then the user will be redirected to that page ErrorDocument 404 http://sitename.com/path/to/404.php # causes redirect If you don't want the redirect to happen then drop the http://sitename.com part from the path. ErrorDocument 404 /path/to/404.php # does not cause redirect The file paths used in your HTML you must then use an absolute url for serving files, whereas with PHP the file paths will be relative to where 404.php is located on the file system. Quote Link to comment https://forums.phpfreaks.com/topic/287118-newbie-question-or-maybe-not/#findComment-1473367 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.