index.php?id=

jamieoliver22

In Runtime
Messages
245
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
 
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?
 
"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
 
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.
 
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
 
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?
 
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
 
Back
Top Bottom