Jump to content

Archived

This topic is now archived and is closed to further replies.

pandacrusader

index.php?page=news.php (Include function)

Recommended Posts

Alright, I've done this before, and it's taking a lot for me to remember exactly how it was done. In a perfect world, one would go to the index.php page consisting of:

[code]<?PHP

include ('top.php');

if (!$page)
{
    $page = "news";
}

include ($page . ".php");

include ('bot.php');

?>[/code]

And be automatically shown the top third, the content in the middle, and the closing third. The links to other content then look something like this:

[code]<li><a href="index.php?page=news">News</a></li>[/code]

However, the result of this script is an include error that's now creating too busy of a server for me (my host must love me =) ).

Any ideas why it can't find the correct file to include? I'm sure it's just a simple matter of syntax, it's been many a moon since I last coded. Thanks much in advance, PHPFreaks has always been timely and decisive!

- Icbat

Share this post


Link to post
Share on other sites
try something like this:
[code]
<?php

include ('top.php');

// first, set a default to drop to if there isn't one in the URL
$page = isset($_GET['page']) ? $_GET['page'] : 'news';

include ("{$page}.php");

include ('bot.php');

?>
[/code]

basically, you've got to remember that whatever page you're trying to include is also in the same directory, but otherwise, you should be golden.

Share this post


Link to post
Share on other sites
[quote author=obsidian link=topic=87665.msg352331#msg352331 date=1141691454]
try something like this:
[code]
<?php

include ('top.php');

// first, set a default to drop to if there isn't one in the URL
$page = isset($_GET['page']) ? $_GET['page'] : 'news';

include ("{$page}.php");

include ('bot.php');

?>
[/code]

basically, you've got to remember that whatever page you're trying to include is also in the same directory, but otherwise, you should be golden.
[/quote]

I tried using this, and it didn't work. I am wondering why. Also, how do you go about putting a default and be able to change what $page is?

Share this post


Link to post
Share on other sites
[code=php:0]
<?php

include ('top.php');

//Why don't we try the old way?
$page = $_GET['page'];
if(isset($page)) { include ('$page.php');} else{ include ('home.php'); }
//not tested yet

include ('bot.php');

?>
[/code]

Share this post


Link to post
Share on other sites

×

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.