...

View Full Version : Crawling PHP includes?



ajhauser
05-01-2009, 07:15 AM
Hello, I am new to includes and I see that when you look at the source code of a page that loaded with PHP includes, all the code is displayed. Does this mean that search spiders will crawl the data that is being included?

For example:


<!DOCTYPE ...>
<html>
...
<body>
<?php include('/path/to/include.ext');?>
</body>


I would imagine one would use a template to include the basic data for a page, like the meta data, etc. - but if you included the meta data in a PHP include, would that be crawled as well?



On a slightly different note - aside from building a completely dynamic, database driven site, is there any better option for site-wide-updates than PHP includes? I have already found them to be better than Server Side Includes and Templates (which update an entire site, but requires the re-uploading of EVERY file on the site).

THANK YOU!
-AJ

Fou-Lu
05-01-2009, 09:10 AM
If you're code is being displayed, then the page isn't being parsed as php - make sure the extension is .php. If the code is html code, that is fine. The page requested includes the definitions from the included file and is seen as the whole picture, not as parts.


<?php
// menu.php
// Something really simple:
session_start();
if (!isset($_SESSION['loggedin']))
{
printf("<a href=\"%s\">%s</a>\n", 'login.php', 'Login');
}
?>



//Index
<?php
session_start();
?>
<!DOCTYPE...>
<html>
<head>
</head>
<body>
<?php include dirname(__FILE__) . '/./menu.php';
</body>

will be seen as:


<!DOCTYPE...>
<html>
<head>
</head>
<body>
<a href="login.php">Login</a>
</body>


Other than PHP, you can approach a client side method instead using XML and XSLT processing. This provides the client with an entire XML document, and formatting provided by the XSLT stylesheet. PHP also has an interpreter in it (xsl or xslt extension) that lets you convert the result to plain html (we needed this back in the day when xml wasn't supported properly by the browsers).

That all make sense?

ajhauser
05-01-2009, 09:44 AM
It KIND of makes sense - my problem is I'm so new still... not your typing. Let me be a little more specific:

My entire page called "index.php", is is located HERE (http://www.temp1.hangnailproductions.com/) and the code is LITERALLY:



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>php</title>
</head>

<body>
<?php include('includes/nav.html'); ?>
</body>
</html>


My include "nav.html" is simply:



<a href="#">Home</a> | <a href="../about.php">About Us</a> | <a href="#">Link 3</a>

NOTE: the links are broken - they aren't relevant for this.

Now, when I look at the source code - it displays as follows:



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>php</title>
</head>

<body>
<a href="#">Home</a> | <a href="../about.php">About Us</a> | <a href="#">Link 3</a></body>

</html>


My question is when Google crawls the site (for example) does is "see" the source code, or will it only see the first example of code with the "<?php include('includes/nav.html'); ?>" - ?

Hopefully that makes sense - thank so much for your help, it has been invaluable to me.

abduraooft
05-01-2009, 01:11 PM
Google or any other search engines are just like a normal user. They can't see the PHP or the server side code. They only see the parsed html output.

ajhauser
05-01-2009, 08:50 PM
OK that completely answers my question - thank you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum