Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 05-15-2006, 11:01 PM   #1 (permalink)
 
Super Techie

Join Date: Dec 2002

Posts: 458

sickness

Default PHP Include Question

So on my main page, index.php, I have a PHP news script installed, FusionPHP, and the news displayed useing a simple PHP include code. I want to know how I can add other pages now, useing the "index.php?page=pageid" form. It's the best I can describe it as. Below is a link to my site.

Right now I have it set up useing Frames, but this is just until I can get the PHP working.

http://www.gamercontrol.com

Thanks.
__________________
<font size=1><b>Current Build:</b>
DFI Lanparty Ultra-D
<a href=\"http://valid.x86-secret.com/show_oc?id=77714\">AMD 64 X2 4400+ @ 2.20GHz</a>
Big Typhoon Heatsink/Fan
2 GB G.Skill DDR500 PC4000
eVGA 256MB 7800GTX
37GB Raptor
2x 120GB Hard Drives</font>
sickness is offline  
Old 05-16-2006, 06:09 AM   #2 (permalink)
 
Ultra Techie

Join Date: Oct 2003

Posts: 544

fitzjj

Default

All you need is a file called index.php which contains the following code:
Code:
<?php
   include(pagesArray[pageid]);
?>
where pagesArray is an array containing the paths to the pages - you may want to use a database here instead, but it is easier to explain with an array.

the array would look something like:
Code:
<?php
   pagesArray[0] = 'some/path/page.htm';
   pagesArray[1] = 'another/path/index.htm';
?>
and would need inserting in the page above the include statement. now the address:
"http://www.example.com/index.php?pageid=1"
will load the page 'another/path/index.htm' into /index.php.

However you wont be able to do this if register_globals is disabled (it is now disabled by default with php). register globals is what enables the passing of variables in the URL. To enable it go into your php.ini file and enable it. Of course if you dont have access to the php.ini file then you wont be able to do this.
fitzjj is offline  
Old 05-20-2006, 10:33 AM   #3 (permalink)
 
Super Techie

Join Date: Apr 2004

Posts: 316

BlazingWolf

Default

Quote:
However you wont be able to do this if register_globals is disabled (it is now disabled by default with php). register globals is what enables the passing of variables in the URL.
Thats wrong. You can still use this kind of naviagation with no problem. But you can't access the varible with $pageid you have to use $_GET['pageid']

The most common way this is done, is to with a switch statement.

PHP Code:
switch($_GET['pageid']
{
case 
"top10":
include(
"top10.php");
break;
case 
"chat":
include(
"chat.php");
break;
default:
include(
"main.php")
break;


And then you would form a link like this

Top 10 of E3

If you really wanted to use numbers for the page idea you would add an array into the middle like the prevouis poster did with the same swith structure but instead using

include(pagesarray[$_GET['pageid']);
__________________
BlazingWolf
<font color=\'red\'>
<b>
<a href=\'http://www.gaming-forums.org\'>
Gaming-Forums.org
<a/>
</b>
</font>
BlazingWolf is offline  
Old 06-16-2006, 03:07 PM   #4 (permalink)
 
Junior Techie

Join Date: Oct 2005

Posts: 75

darkninja

Default

Quote:
The most common way this is done, is to with a switch statement.
I think there may be an easier way, otherwise, if you have a billion pages, its a bit hard to keep adding switch statements

Code:
<?php
if ($_REQUEST[pageid]) {
      require "$_REQUEST[pageid].php";
}
?>
That way, every time you need to add a new page you dont need to add another switch statement.

You link to it the same way.

Quote:
Top 10 of E3
Hope that helps
__________________
<a href="http://www.flashyflashy.net" target="_blank">flashyflashy.net</a>
darkninja is offline  
 
Closed Thread

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