Single PHP page for full website

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mcallinder
Forum Newbie
Posts: 3
Joined: Wed Feb 02, 2011 2:36 pm

Single PHP page for full website

Post by mcallinder »

Hello, just a general concept question: I was wondering if it is possible to create a small website (less than 10 pages) using a single index.php. Basically I want the links to reload the page with a different name variable which leads to different content being displayed. Is this doable without a cookie? Also, if it is possible, would it hurt the site's SEO?

If it is possible to do this, any thoughts on a good way to change the name variable through a link click?

Thanks.
User avatar
phazorRise
Forum Contributor
Posts: 134
Joined: Mon Dec 27, 2010 7:58 am

Re: Single PHP page for full website

Post by phazorRise »

You can drive all site with single page. Here's sample code.

Code: Select all

<?php
error_reporting(E_ALL);

if(isset($_GET['pageName'])){
$p=$_GET['pageName'];
}
if(!empty($p)){
	switch($p){
		case "page1":{
			echo 'You are on page 1<br/>';
		}
		break;	
		case "page2":{
			echo 'You are on page 2<br/>';
		}	
		break;
		case "page3":{
			echo 'You are on page 3<br/>';
		}	
		break;
		case "page4":{
			echo 'You are on page 4<br/>';
		}
		break;	
		default:{
			echo 'Page Not Found !<br/>';
		}
		break;		
	}
}
else{
	echo 'Default Page or inlcude template<br/>';	
}
	echo 'Navigation Template<br/>';
	echo '<a href="'.$_SERVER['PHP_SELF'].'?pageName=page1"> page 1<a><br/>';
	echo '<a href="'.$_SERVER['PHP_SELF'].'?pageName=page2"> page 2<a><br/>';
	echo '<a href="'.$_SERVER['PHP_SELF'].'?pageName=page3"> page 3<a><br/>';
	echo '<a href="'.$_SERVER['PHP_SELF'].'?pageName=page4"> page 4<a><br/>';

?>
Things to remember -
-> Clean user input/urls before ( i've skipped that thing here ).
-> Doing this will be kind of procedural thing so take care of control flow.
-> Templating might be difficult for this thing.
-> If database involved, take security measures. take care while opening/closing connections, freeing results.
-> You can use apache's mod_rewrite module to make urls appear like site is not single page. for example -

Code: Select all

          echo '<a href="section/pageNo"> Section->Page </a>';
will appear in url something like -
[text]http://www.domain.com/section/pageNo[/text] If you're not familiar with mod_rewrite study it first. That will help in SEO also..

I might have missed somethings but others will add into it.

I don't have much idea about SEO things, so i don't want to give wrong advice anyhow.
mcallinder
Forum Newbie
Posts: 3
Joined: Wed Feb 02, 2011 2:36 pm

Re: Single PHP page for full website

Post by mcallinder »

This works very well, exactly what I had in mind. Thank you very much.

If anyone else reads this with additional SEO thoughts on using a single page like this, I'd love to hear them.
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: Single PHP page for full website

Post by phphelpme »

This will not effect your rankings as long as you give specific addresses like phazorRise suggested using mod_rewrite etc. Also making sure you have good content and lots of it to compete with already existing websites that search engines visit. Search Engines love content!

Another important thing is if you are not having lots of content compared to your competitors then make sure develop a great linking system around your pages (or page should I say... lol) a good linking system will allow such search engines as Google to detect your pages quickly and enter them into the database.

Stay clear of addresses that use x=y&y=x&Z=a& & & etc. Google struggles keeping content upto date with urls like that as it is generally database driven. So nice clean urls liek suggested above which to me is the most important factor for your situation as you mentioned you are only going to have 10 pages which I could assume 90% of those pages are going to be static and unchanged content.

Google loves content so if you want to compete then give it what it wants.

Think about it and then think Wordpress. lol Wordpress content is generated from a database via a simple template which is replicated over and over again in the browser.

The important thing is to treat each case in the code suggested above as a seperate page and optimise it for the content you are displaying as you normally would for an individual page. Including headers and footers etc with body content. Use clean HTML and CSS to markup your pages from within your index.php function file.

I see no issues in your theory and it is widely used accross the web.

Best wishes
Post Reply