View Full Version : how to create index.php?id=1
wreed
November 16th, 2002, 12:22
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
kabatak
November 16th, 2002, 12:28
Do you mean like this?
<?
if (!$id || $id =="")
{ include("page.html"); }
else
{ include("$id.html"); }
?>
wreed
November 16th, 2002, 14:00
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 :)
wreed
November 16th, 2002, 14:08
http://www.4gigs.com/~forgot/index.php?id=test
Ok, So I played around with it and figured it out, thanks to you :)
But, What do I do if I want to have more than 1? I'd like to have about 5-10 of these, and I cannot figure out what is needed to have more than one.
Thanks,
-Reed
spec
November 16th, 2002, 19:58
Stick your content in txt files.
<?
$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.
The Red Guy
November 16th, 2002, 23:03
I think this is easier, just adding more from the first example
<?
if (!$id || $id =="1")
{ include("page1.html"); }
elseif (!$id || $id =="2")
{ include("page2.html"); }
else
{ include("$id.html"); }
?>
Just add more elseif statements. :)
Ben
November 17th, 2002, 02:32
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:
<?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.
hohoho
November 17th, 2002, 03:04
ben, the if/else part should be above the include
GameSource
November 17th, 2002, 05:51
Heres somethin I use on my site, a friend helped me out with it.
<?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.
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.