View previous topic :: View next topic |
Author |
Message |
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Tue Feb 08, 2005 9:03 pm Post subject: PHP Pages |
|
|
Hello,
I am fairly new to the world of PHP and I was wondering how I incorporate serveral pages into one php script page such as index.php and then add ?mypage to the end of the filename to bring up another page.
E.G http://www.m3ezw.co.uk/index.php?home will bring up the homepage
http://www.m3ezw.co.uk/index.php?downloads will bring up the downloads page.
I have seen this done with many scripts and have spent hours trying to do it myself but I can never seem to get it to work. Any simple script on how to get this to work will be greatly appriciated.
Thanks. _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
 |
MonkeyNation -
Joined: 05 Feb 2005 Posts: 921 Location: Cardiff
|
Posted: Tue Feb 08, 2005 10:46 pm Post subject: |
|
|
It took me a while to figure this out too. But its so simple.
http://62.249.233.57/test6.php?georgebush=retarded
http://62.249.233.57/test6.php?georgebush=normal
They will bring up different text each time.
The source to this is Code: |
<?php
$gb = $_GET['georgebush'];
if ($gb == "retarded") {
echo "YO DAMN RIGHT!";
}
if ($gb == "normal") {
echo "WTF ARE YOU TAKING, YOU KNOW YOUR WRONG!";
}
?>
|
Its the $_GET that does this, if you were to do $_GET['page'] then you would end up with page? . But im sure you've figured this by now.
There are probably other ways of doing this, but this is the only way I have.
Have fun with it :D _________________
 |
|
Back to top |
 |
 |
Glitch2082 -
Joined: 02 Dec 2004 Posts: 194
|
Posted: Tue Feb 08, 2005 11:17 pm Post subject: |
|
|
You can also use case etc...
But the way your doing it you would use include, instead of echoing it in order to go to the page. Just thought I should inform 'The Inquister' of this. _________________ int main() {
cout << "Im Pro Apache";
cin.get();
} |
|
Back to top |
|
 |
mrkill47 -
Joined: 12 Jan 2005 Posts: 17 Location: 127.0.0.1
|
Posted: Wed Feb 09, 2005 1:18 pm Post subject: |
|
|
make a page template with all your layout info and stuff.
in the part where the content should go put:
Code: | $_GET['page'] = isset($_GET['page']) ? $_GET['page'] : NULL;
switch( $_GET['page'] ) {
case 'test' :
include 'test.php';
break;
case 'about' :
include 'about.php';
break;
case 'forum' :
include 'forum.php';
break;
default:
include 'main.php';
break;
}
|
If someone goes to http://www.yoursite.com/index.php?page=about it will show the about page. what the php script will do is include the contents of the file "about.php" (which is just raw content).
you can edit the code above to suit your site. i have also included a default case so that if someone goes to www.yoursite.com/index.php (with the ?page=) it will include a default page. _________________ http://fnar.sytes.net <<--- Powered by Abyss :D |
|
Back to top |
|
 |
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Wed Feb 09, 2005 6:01 pm Post subject: |
|
|
Thanks for your help, I am going to give it a go now.
The address for the site I will be using it for is http://82.9.140.66 but it won't be online until sunday.
Cheers. _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
 |
MonkeyNation -
Joined: 05 Feb 2005 Posts: 921 Location: Cardiff
|
Posted: Wed Feb 09, 2005 6:25 pm Post subject: |
|
|
mrkill47 wrote: | make a page template with all your layout info and stuff.
in the part where the content should go put:
Code: | $_GET['page'] = isset($_GET['page']) ? $_GET['page'] : NULL;
switch( $_GET['page'] ) {
case 'test' :
include 'test.php';
break;
case 'about' :
include 'about.php';
break;
case 'forum' :
include 'forum.php';
break;
default:
include 'main.php';
break;
}
|
If someone goes to http://www.yoursite.com/index.php?page=about it will show the about page. what the php script will do is include the contents of the file "about.php" (which is just raw content).
you can edit the code above to suit your site. i have also included a default case so that if someone goes to www.yoursite.com/index.php (with the ?page=) it will include a default page. |
Thanks also, I learnt somthing new today :D _________________
 |
|
Back to top |
 |
 |
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Wed Feb 09, 2005 8:59 pm Post subject: |
|
|
This script is perfect and just what I was looking for, thanks mrkill47! _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
 |
|