• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

how to create index.php?id=1

wreed

New Member
Would anyone know how to do this.
I would like to create a website in PHP, which I mostly know, But I do not know how to create something like that. If anyne could help, it would greatly be appreciated.

Thank you,
-Reed
 
Do you mean like this?
PHP:
<?
if (!$id || $id =="")
{ include("page.html"); }
else
{ include("$id.html"); }
?>
 
I belive that may work, altho, I belive that you need to have it .php and not html. Thank you for your quick response, as it was greatly needed :)
 
Stick your content in txt files.
PHP:
<?
$index[0] = "page.txt";
$index[1] = "page1.txt";
$index[2] = "page2.txt";
$index[3] = "page3.txt";
$index[4] = "page4.txt";

if(isset($id)) {
$contentpage = $index[$id];
include($contentpage);
}
else include($index[0]);
?>

index[0] will be your homepage.
 
I think this is easier, just adding more from the first example

PHP:
<?
if (!$id || $id =="1")
{ include("page1.html"); }
elseif (!$id || $id =="2")
{ include("page2.html"); }
else
{ include("$id.html"); }
?>

Just add more elseif statements. :)
 
I prefer this way:

Say you've got main.php, news.html, and pictures.html. main.php contains the layout, news.html contains the news, and pictures.html contains your baby pictures.

You put this into main.php where the site content would go to make it show the news when someone goes to just main.php:
Code:
<?php
include("$id.html");
if ($id == "") {
$id == news;
)
else {
$id == $id;
}
?>

Then you want to tell everyone about your baby pictures you uploaded (why? no idea). You would add a link to main.php?id=pictures and it would show the pictures page instead of the news. Dynamically generating pages....

I hope I explained this well.
 
Last edited:
Heres somethin I use on my site, a friend helped me out with it.

PHP:
<?php 
$filename = "$id.txt"; 
if (strtolower($id) == "index" or $id == Null) {  
include('news.txt'); 
} elseif(!file_exists($filename)) {                

include('404.txt'); 
} else {  
include("$filename"); 
} 
?>

You can probably change the .txt stuff to anything, I just prefer including text files in my page, alot easier.
 
Back
Top