Jump to content

Recommended Posts

Posted

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.

Posted (edited)

Ok, Im lost but thats ok. ;)

Thanks anyway Mike J :D

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 by Jikrantz
Posted

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. =)

Posted

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.

Posted
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 :D

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. ;)

Posted

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. :D Try to structure so that all your includes go to one page where you can.

Posted

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. :D

Posted

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.

Posted (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? :D

Edited by Jikrantz
Posted (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 by TCH-Lisa
Posted

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

Posted (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 by TCH-Lisa
Posted

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.

Posted

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.

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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