Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 01-02-2005, 05:32 AM   #1 (permalink)
dakota47
Registered User
 
Join Date: Jan 2005
Posts: 1
dakota47 is on a distinguished road
Question Using parsed variable to call includes

Hello All,

My situation is that I have a standard template whereby the main content is displayed via include files. The include is called as below, with the variable ($page) being labelled and parsed to each page via the links to their respective pages.

Extremely simplified example...

<body>
<?
include ($page.".php");
?>
</body>
</html>


My problem stems from the inital page loading (default.php). How can i assign a value to $page so the initial page loads with the appropriate include, yet each subsequent page load uses the value of $page that is parsed via the clicked link?

I hope that makes sense, my brain hurts.

Cheers

Rob Smith
Canberra, AUSTRALIA
dakota47 is offline   Reply With Quote
Old 01-02-2005, 08:39 AM   #2 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
So if no "page" is specified it'll load default.php ?

Something like:
(some paranoia checking added for general purpose)

PHP Code:
$page = ($_GET['page']) ? $_GET['page'] : 'default';
$page basename($page);

$include "$page.php";

if (
file_exists($include)) {
   include 
$include;
}
else {
  echo 
"error - page does not exist."

idx is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing variable type for edit box : mfc - .net sde Standard C, C++ 0 01-31-2003 10:53 AM
creating dynamic variable names sde PHP 5 11-02-2002 10:03 AM


All times are GMT -8. The time now is 07:41 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting