Jump to content


Photo

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


  • Please log in to reply
4 replies to this topic

#1 pandacrusader

pandacrusader
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 07 March 2006 - 12:27 AM

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:

<?PHP 

include ('top.php');

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

include ($page . ".php");

include ('bot.php');

?>

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:

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

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



#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 07 March 2006 - 12:30 AM

try something like this:
<?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');

?>

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.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 pandacrusader

pandacrusader
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 07 March 2006 - 01:38 AM

Makes sense. Thanks, Obsidian! You've helped a lot!

#4 ricez

ricez
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 10 August 2007 - 03:12 AM

try something like this:

<?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');

?>

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.


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?

#5 felipeebs

felipeebs
  • Members
  • PipPipPip
  • Advanced Member
  • 58 posts

Posted 10 August 2007 - 03:22 AM

<?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');

?>


I'll be back... tomorrow... maybe... I don't really know... -.-"




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users