Jump to content


Photo

I tried searching but...


  • Please log in to reply
4 replies to this topic

#1 HasmanNNC

HasmanNNC
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 18 August 2006 - 06:44 AM

... I couldn't find anything to properly answer my question. I read the PHP Faq, and the link for the rest of Dynamic URLs was dead. Its a stupid question, I know, but I really need help, so please dont just hit back :P

Anyways, I wanted to display my content as: http://www.domain.co...ge=whatever.htm

Before I had bought a host, I was using hostultra and the following script worked:

<?php include ("$page"); ?>

I would type that where I wanted the external page to display, and it would display there automatically. This way, I could create a page with only text and it would display on the index.php file providing I typed the correct URL. However, I recently bought a server from GoDaddy and I transfered my website over, but the include didn't work. Instead, I was forced to create a seperate PHP file for every page and include a header.php and menu.php. I realised that if ever I want to change layouts, I'll have to change every single page. I'm wondering how I can fix this problem, and whether or not its a matter of editing php.ini or not. I know this is a dumb question, but the dumber, the easier to answer right? Please help me. If

#2 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 18 August 2006 - 06:54 AM

Put this on your index page where you want the content to be displayed (generally somewhere under your header and above your footer):

	$pathToMainPage = "index.php";
	$pathTo404Page = "404.php";
	if(isset($_GET['page']))
	{
		$pathToIncludePage = $_GET['page'].=".html";
		if(file_exists($pathToIncludePage))
		{
			include $pathToIncludePage;
		}
		else
		{
			include $pathTo404Page;
		}
	}
	else
	{
		include $pathToMainPage;
	}
You will need to change the paths to your main page and 404 page. With that you should be able to access a page via: http://www.domain.co...p?page=whatever
Note: you do not need to include the .html

#3 HasmanNNC

HasmanNNC
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 18 August 2006 - 07:12 AM

Thanks for the quick reply :) Do I change the $pathToIncludePage; to $http://www.domain.com/whatever.htm; or the absoulute path? like $/home/h/a/s/public_HTML/whatever.htm ?

#4 hostfreak

hostfreak
  • Members
  • PipPipPip
  • Advanced Member
  • 581 posts

Posted 18 August 2006 - 07:39 AM

Leave the $pathToIncludePage as is. The only time you would change anything within it would be if you wanted to include a different extension (say .php instead of .html) or want to change the (page?=) to something like (id?=). Then for the 404.php, just use 404.php or whatever your error page is. On the $pathToMainPage = "index.php"; you can include your news or what have you.

#5 HasmanNNC

HasmanNNC
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 18 August 2006 - 07:46 AM

Many thanks! Problem is solved and it finally works. :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users