Go Back   Computer Forums > Web Design | Website Development > Web Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 12-20-2005, 03:43 PM   #1
In Runtime
 
jamieoliver22's Avatar
 
Join Date: Apr 2004
Posts: 245
Default index.php?id=

Hello.

How exactly do you use index.php?id=?

For example. I have a page with links and I want to link to index.php in the news folder. So I added index.php?id=news/index as the link thinking that it would work.

How do you make it work?

Thanks
Jamie
__________________

jamieoliver22 is offline   Reply With Quote
Old 12-21-2005, 09:27 AM   #2
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,007
Default Re: index.php?id=

can you be a little more specific as to what you are trying to do?

are you trying to make something where the page content changes depending on the thing given, or are you trying to make menu links appear on a page so that you only have to update one menu file at any time?
__________________

__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 12-21-2005, 10:42 AM   #3
In Runtime
 
jamieoliver22's Avatar
 
Join Date: Apr 2004
Posts: 245
Default Re: index.php?id=

"are you trying to make something where the page content changes depending on the thing given"

^ Yes..

I want the page to change to what ever is on the index.php file in each folder.

Thanks
J
jamieoliver22 is offline   Reply With Quote
Old 12-22-2005, 08:00 AM   #4
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,007
Default Re: index.php?id=

OK...


Just use this...

set up a folder structure like this...
Code:
root
|-index.php
|-menu.html
|-pages <this is a folder
|  |-news.html
|  |-main.html
|  |-contact.html
|-images <this is a folder
Right...

now write your index page like this...
Code:
<?php
$page = $_REQUEST['id'];

print "<html><head><title>My Page</title></head>

<body>
";
include('menu.html');

switch(page)
{
case default:
include('pages/main.html');
break;

case 'news':
include('pages/news.html');
break;

case 'contact':
include('pages/contact.html');
break;
}
print "</body></html>";
?>

so you see... now when you open the site, index.php displays the menu file and the contents of the main.html page...

if you go to index.php?id=news
then it'll display the news page from the pages folder.

(it also has that addes bonux of only having one menu file to update as well...).


When you write the html pages, write them as if they were in the root folder as well...

so to link a picture just put <img src="images/test.jpg"> not <img src="../images/test.jpg">

because the page is rendered as if it were a part of the file index.php since it's called from that file.
__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 12-22-2005, 10:38 PM   #5
Daemon Poster
 
draconum's Avatar
 
Join Date: Mar 2005
Posts: 1,365
Send a message via AIM to draconum Send a message via MSN to draconum
Default Re: index.php?id=

or you an do something like this as well:

Code:
<?php
$get = $_GET['id'];
$page = array('id' = 'news');

include("folder/$page[$get].php");
?>
I use that a bit in my coding.


Chris
__________________
My Computer:
Mother Board: MSI K8N Neo4 Platinum/SLI --- CPU: AMD Athlon 64 3200+
PSU: OCZ ModStream 520w ----------------- HD: Seagate Barracuda 200g
Video Card: XFX GeForce 6200 -------------- RAM: OCZ Value ram Dual Channel 256 x2
draconum is offline   Reply With Quote
Old 12-23-2005, 04:57 AM   #6
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,007
Default Re: index.php?id=

that's certainly a more compact way of doing things!!

don't understand why you need this line though...

$page = array('id' = 'news');


it could just be

<?php
$page = $_GET['id'];
include("folder/$page.html");
?>



of course to make it practical


<?php
$page = $_GET['id'];
include('header.html');
include('menu.html');
include('pages/$page.html');
include('footer.html');
?>



anyway... Jamie... has that answered the question?
__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 12-24-2005, 11:06 PM   #7
Daemon Poster
 
draconum's Avatar
 
Join Date: Mar 2005
Posts: 1,365
Send a message via AIM to draconum Send a message via MSN to draconum
Default Re: index.php?id=

Well, I used todo the same thing untill I heard from another forum I look around sometimes that it can sometimes be unsecure letting any string be included. So putting the file names in an array makes sure that the file actually exists before it's included, instead of just including any file.
ex:
with the $page = $_GET['id'];
include ("folder/$page.php");

somebody could type say: index.php?id=../../../root/mainsystemfilethatisvitaltotheserverrunning.dll
or something silly like that, so having it in a predefined string makes sure this type of thing doesn't happen.


Chris
__________________
My Computer:
Mother Board: MSI K8N Neo4 Platinum/SLI --- CPU: AMD Athlon 64 3200+
PSU: OCZ ModStream 520w ----------------- HD: Seagate Barracuda 200g
Video Card: XFX GeForce 6200 -------------- RAM: OCZ Value ram Dual Channel 256 x2
draconum is offline   Reply With Quote
Old 12-25-2005, 06:19 AM   #8
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,007
Default Re: index.php?id=

Hadn't even thought of that...!

Good point...
__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 12-26-2005, 04:35 AM   #9
Dvx
Baseband Member
 
Join Date: Nov 2005
Posts: 32
Default Re: index.php?id=

like my site?
http://dzx.elusivedesignz.net/?sn=Computerforums.org
thats what i use to track people with like with the ips and stuff heres where the information goes to
http://dzx.elusivedesignz.net/tracker.php
__________________

Dvx is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off



All times are GMT -5. The time now is 10:21 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0