Bart Humphries Bart Humphries - 2 months ago 6
Ajax Question

SEO with PHP include switch statements (so the page changes dynamically like JavaScript)

As you can see, in the following code, it dynamically calls itself again and changes what's on the page when a button is clicked (through PHP includes). Would this hurt search engine optimization or are companies like Google smart enough to notice that the file could be included here then go look up the other files in the directory?

<!DOCTYPE html>
<html>
<head>
<title>Web Template</title>
</head>
<body>
<?php include ("inc_header.html"); ?>
<div style = "width:20%; text-align:center; float:left">
<?php include ("inc_buttonnav.html"); ?>
</div>
<!-- Start of Dynamic Content section -->
<?php
if (isset($_GET['content'])) {
switch ($_GET['content']) {
case 'About Me':
include('inc_about.html');
break;
case 'Contact Me':
include('inc_contact.html');
break;
case 'Home': // A value of 'Home' means to display the default page
default:
include('inc_home.html');
break;
}
}
else // No button has been selected
include('inc_home.html');
?>

<!-- End of Dynamic Content section -->

<?php include ("inc_footer.php"); ?>

</body>
</html>


Ok, I hadn't looked at the browser-parsed code. Here's what the browser sees for Home and About.

Home:

<!DOCTYPE html>
<html>
<head>
<title>Web Template</title>
</head>
<body>
<h1 style="text-align: center">Sample Web Template</h1>
<div style = "width:20%; text-align:center; float:left">
<form action="WebTemplate.php" method="get">
<input type="submit" name="content" value="Home" /><br />
<input type="submit" name="content" value="About Me" /><br />
<input type="submit" name="content" value="Contact Me" /><br />
</form>
</div>

<!-- Start of Dynamic Content section -->

<h2>Home Page</h2>
<p>This is the default home page that displays
whenever a new visitor comes to the site</p>

<!-- End of Dynamic Content section -->

<p>Today's Date: Tue, 21 Oct 2014 05:42:41 +0000</p></body>
</html>


About:

<!DOCTYPE html>
<html>
<head>
<title>Web Template</title>
</head>
<body>
<h1 style="text-align: center">Sample Web Template</h1>
<div style = "width:20%; text-align:center; float:left">
<form action="WebTemplate.php" method="get">
<input type="submit" name="content" value="Home" /><br />
<input type="submit" name="content" value="About Me" /><br />
<input type="submit" name="content" value="Contact Me" /><br />
</form>
</div>

<!-- Start of Dynamic Content section -->

<h2>About Me</h2>
<p>This is the page that tells about me and my Web
site.</p>

<!-- End of Dynamic Content section -->

<p>Today's Date: Tue, 21 Oct 2014 05:43:02 +0000</p></body>
</html>


I guess that would be particularly dense and hard to follow for Googlebot. I suppose I could try to depend on a good sitemap, but maybe it would be better to just have a more plain website.

Answer

You pages have different URL's, like:

http://www.example.net/mypage.php?content=about
http://www.example.net/mypage.php?content=contact
http://www.example.net/mypage.php?content=home

Most search engines treat those as potentionally different pages. And when they load them, and they are different, then they will be seen as different.

Comments