TCH-Thomas Posted September 22, 2004 Posted September 22, 2004 I havent much experience with php includes yet, so excuse for an eventual dumb question Is there anything that is not smart to make as an include? Quote
MikeJ Posted September 22, 2004 Posted September 22, 2004 Be careful using variables in your include. <?php require($content); ?> is very bad if you don't explicity define $content in your script. This is the most common mistake I see in PHP scripts that gets abused. If you don't explicitly define it in your script (or sanitize it), the variable can be defined in the URL, and you can probably imagine why that's a bad thing. Quote
TCH-Thomas Posted September 22, 2004 Author Posted September 22, 2004 (edited) Ok, Im lost but thats ok. Thanks anyway Mike J The includes I am thinking of is similar to this ><?php include('http://www.domain.com/menu.php'); ?> And what I mean is, is there something like images, certain scripts etc that is not smart to include (like logo.gif etc)? Edited September 22, 2004 by Jikrantz Quote
LisaJill Posted September 22, 2004 Posted September 22, 2004 Php includes are written, on the fly, into the page. So when you include them when you load the page and view source, then you'll see it as though it were all built in there. For that reason, you want to continue to avoid things like "banner.gif" that Norton or other security agents will block as advertisements. Embedding php includes is possible too - but be careful how much you do that, each one is a seperate call on the server, so you don't want to be crazy about it. =) Quote
TCH-Thomas Posted September 22, 2004 Author Posted September 22, 2004 Embedding php includes Im sorry Lisa but now Im more lost. Quote
TCH-Don Posted September 22, 2004 Posted September 22, 2004 Thomas you should always include as <?php include $_SERVER['DOCUMENT_ROOT']."/menu.php"; ?> do not use the http:// address as included file cannot pass data to the main page, at least I think that is what Raul said. And this way no matter where you move the file that is including the menu, it will still work as opposed to just <?php include("menu.php"); ?> which points to the current folder. Quote
TCH-Thomas Posted September 22, 2004 Author Posted September 22, 2004 Thomas you should always include as <?php include $_SERVER['DOCUMENT_ROOT']."/menu.php"; ?> do not use the http:// address as included file cannot pass data to the main page, at least I think that is what Raul said. And this way no matter where you move the file that is including the menu, it will still work as opposed to just <?php include("menu.php"); ?> which points to the current folder. Ok, will do that Don So to include one menu for my own personal site and a different one for the webring for instance I would just have to name them differently, like personalmenu.php and webringmenu.php? Sorry for all questions, but Im just trying to extend my knowledge. Quote
LisaJill Posted September 22, 2004 Posted September 22, 2004 What I meant by embedding is having a php include within another include within another include.... on and on; don't go crazy with that. Try to structure so that all your includes go to one page where you can. Quote
TCH-Bruce Posted September 22, 2004 Posted September 22, 2004 I have a question that relates to PHP includes. When the search engines are crawling your site are the include files included with the page as it's being spidered? I am reworking our company site and moving some stuff into includes but need to know the answer if there is one. I am assuming that it does but would like someone who might know confirm please. Quote
TCH-Thomas Posted September 22, 2004 Author Posted September 22, 2004 don't go crazy with that No worries, Im still on pre-kindergarten stage Quote
LisaJill Posted September 22, 2004 Posted September 22, 2004 Search engines see the site as you would see it if you were to view source. Basically, there is noway that you (or the search engines) would know if it were a php include; because it's written into the actual page. (try viewing source, you won't see the php include statement, you'll see what was inside the included file) So, in answer - search engines will still spider it as if it were built onto the page. Quote
TCH-Thomas Posted September 22, 2004 Author Posted September 22, 2004 (edited) I tried uploading a php file now to my public_html/root directory to have some text showing in the webring. I called the file moreways.php and inserted this to the page the text is supposed to show up on: <?php include $_SERVER['DOCUMENT_ROOT']."/moreways.php"; ?> This page is for the moment in a test folder and if the php file is also in the test folder it works great, but if php file is in root directory then the following error appears Warning: main(/home/cpanelusername/public_html/tchwebring/moreways.php): failed to open stream: No such file or directory in /home/cpanelusername/public_html/tchwebring/test/index.html on line 284 How come? Edited September 22, 2004 by Jikrantz Quote
LisaJill Posted September 22, 2004 Posted September 22, 2004 (edited) Try getting rid of that document root stuff if it's in the root.... or you'll just telling it to repeat the root path =) <?php include("/menu.php"); ?> Edited September 22, 2004 by TCH-Lisa Quote
TCH-Thomas Posted September 22, 2004 Author Posted September 22, 2004 Ok Lisa. Just did as I understood Dons message above. Quote
TCH-Thomas Posted September 22, 2004 Author Posted September 22, 2004 Done and now I get this error: Warning: main(/moreways.php): failed to open stream: No such file or directory in /home/cpanelusername/public_html/tchwebring/test/index.html on line 284 Warning: main(): Failed opening '/moreways.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/cpanelusername/public_html/tchwebring/test/index.html on line 284 Quote
LisaJill Posted September 22, 2004 Posted September 22, 2004 (edited) Where, exactly, is moreways.php? you need to call it using a root relative url. /moreways.php would be in public_html. if it's in say "test" it needs to be /test/moreways.php" or then you can use document root if you want to. =) Actually, hrm, I'm wrong here - with php I think you need to use document root or write out the full path, ie /home/username/public_html/moreways.php or /home/username/public_html/test/moreways.php if it's in test. that document root statement replaces /home/username/public_html i believe =) I don't use it so not totally sure. Edited September 22, 2004 by TCH-Lisa Quote
TCH-Thomas Posted September 22, 2004 Author Posted September 22, 2004 Ok, will try that tomorrow. Right now its almost 11.30pm here and I am zzzzzzzzzz.... Quote
MikeJ Posted September 22, 2004 Posted September 22, 2004 PHP includes are absolute (so including "/file.php" will look at the root directory of the server, not your website). Using the $_SERVER['DOCUMENT_ROOT'] variable will point to the document root of the site you are accessing. The reason your include was failing was because you are accessing your tchwebring subdomain, so it's document root is the tchwebring subdirectory under public_html, and you are trying to include a file that is in your public_html directory which is the parent directory of your subdomain (the directory above your document root). There's a couple ways you can include that file that should work (Both include the file from the same location, which is the public_html directory of your main account): <?php include("/home/cpanelusername/public_html/moreways.php"); ?> This explicitly defines where the file is. or <?php include $_SERVER['DOCUMENT_ROOT']."/../moreways.php"; ?> This looks in the directory above (/../) the document root for the file. Hopefully I was clear enough for that to make sense. Quote
TCH-Bruce Posted September 22, 2004 Posted September 22, 2004 Search engines see the site as you would see it if you were to view source. Thanks Lisa, I had assumed this to be the case. Just wanted verification. Quote
borfast Posted September 23, 2004 Posted September 23, 2004 Thomas, I didn't read every post in this thread (sorry, my eyes are almost popping out, need to get some sleep) but here's some info that you might find useful: http://www.totalchoicehosting.com/forums/i...indpost&p=68879 Quote
TCH-Thomas Posted September 23, 2004 Author Posted September 23, 2004 <?php include("/home/cpanelusername/public_html/moreways.php"); ?> Works Thanks Monkey Guru Quote
TCH-Don Posted September 23, 2004 Posted September 23, 2004 Thomas, it might be easier to create a folder below the subdomain folder for includes. Such as domain/subdomainfolder/inc which will also look like subdomin.domain/inc then you can use <?php include $_SERVER['DOCUMENT_ROOT']."/inc/moreways.php"; ?> And if in the future you decide to make the sub domain it own domain, the coding will not have to change. Quote
TCH-Thomas Posted September 23, 2004 Author Posted September 23, 2004 Don, let me hear you confess it now. You are a mindreader. I was thinking last night that I should ask if collecting all includes in to one subfolder would work. Quote
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.