Jump to content

Making &page include Work


bobbit

Recommended Posts

Heya!

 

I've been struggling with this for the best part of forever.

 

On the main index of my website I have the following code to include other pages of my site:

 

<? 
if (isset($_GET['page'])) $page = $_GET['page'];
else $page = "home";
if (file_exists("$page.php")) include("$page.php");
else echo "Sorry but the page you requested doesn't appear to exist.";
?>

 

However there is a page that I'm trying to design that needs a similar code in it. Obviously the new page displays with the above include code, but in that page I need its own include code as it's a miniature website within itself.

 

I'm hoping that I can make the address look something like http://www.website.com/?page=newpage&id=videos. So far all I've done is failed :D

 

Sorry if that makes no sense!

Link to comment
Share on other sites

So I gather that someone clicks on a link, technically remains within the same page (we will call this page index.php), but a new page is included? 

That is strange and horrible for SEO.  Are you sure that you don't need to use absolute paths in the file_exists function?  What happens when you

run this?  Is it even making it into the IF block that contains the include function?  What steps have you taken to troubleshoot this...

 

ps. please format code pretty :)

 

<? 
if (isset($_GET['page'])) 
{
$page = $_GET['page'];
}
else 
{
$page = "home";
}

if(file_exists("$page.php"))
{
include("$page.php");
}
else 
{
echo "Sorry but the page you requested doesn't appear to exist.";
}
?>

Link to comment
Share on other sites

So I gather that someone clicks on a link, technically remains within the same page (we will call this page index.php), but a new page is included? 

That is strange and horrible for SEO.  Are you sure that you don't need to use absolute paths in the file_exists function?  What happens when you

run this?  Is it even making it into the IF block that contains the include function?  What steps have you taken to troubleshoot this...

 

I'm not great at PHP - all I know is the code I gave works fine for one-page includes. All I need to know is how to include a page within an include page.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.