Jump to content

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


pandacrusader

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

Link to comment
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.
Link to comment
Share on other sites

  • 1 year later...
[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?
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.