
09-05-2002, 08:15 PM
|
|
Disabled
|
|
Join Date: Aug 2002
Posts: 17
|
|
PHP - loading page inside a layout
Hi, I currently have a gaming site which I just started about a day ago, it is www.gamingexpertz.com, well to get to the main point, I converted the index to php and I want to know how to load a page within the index.php. For example, if you go to www.gamingexpertz.com/index.php you will see the front page of my website, but when I do www.gamingexpertz.com/index.php?page=joinstaff it takes me back to index.php. How do I make this work? Basically I want someone to show me how to load a page inside a layout. I am fairly new in php
Thank you!
|

09-05-2002, 08:20 PM
|
|
iNET Interactive
|
|
Join Date: May 2001
Location: Dayton, Ohio
Posts: 4,869
|
|
PHP Code:
if ($page== "joinstaff") {
include("joinstaff.inc");
}
Add that, and put the info you want on joinstaff into joinstaff.inc...
__________________
-Mat
|

09-05-2002, 08:28 PM
|
|
Disabled
|
|
Join Date: Aug 2002
Posts: 17
|
|
In what part of the page do I put that, prohacker? Can someone tell me an easier way?
|

09-05-2002, 08:53 PM
|
|
Web Hosting Guru
|
|
Join Date: May 2002
Posts: 344
|
|
Sample index.php page:
PHP Code:
<html>
<head>
<title>Your title</title>
</head>
<body>
<?php
if ($page== "joinstaff") {
include("joinstaff.inc");
}
?>
</body>
</html>
Sample joinstaff.inc:
Then just add more if statements into the index.php file for other pages:
PHP Code:
<?php
if ($page== "joinstaff") {
include("joinstaff.inc");
}
if ($page== "links") {
include("links.inc");
}
if ($page== "forums") {
include("forums.inc");
}
if ($page== "something") {
include("something.inc");
}
?>
__________________
Chris Miller
PromoPunch
Custom Imprinted Promotional Products
www.promopunch.com 1-800-750-8530 x221
|

09-05-2002, 08:56 PM
|
|
Disabled
|
|
Join Date: Aug 2002
Posts: 17
|
|
thanks a lot ! that really helped
|

09-05-2002, 09:13 PM
|
|
Disabled
|
|
Join Date: Aug 2002
Posts: 17
|
|
Thank you so much for the help, but I have one problem now... if you look at www.gamingexpertz.com/index.php?page=joinstaff, you will see I have an alignment problem! Will someone please help me fix that.
Thanks a lot 
|

09-06-2002, 06:18 PM
|
|
Web Hosting Master
|
|
Join Date: Nov 2000
Posts: 3,042
|
|
<?php
switch($page) {
case joinstaff:
include("joinstaff.inc");
break;
case links:
include("links.inc");
break;
default:
include("home.inc");
}
The reasons why to use switch:
The more $page values you have the faster the script will run, since it only has to process $page once, instead of multiple times. It really isn't a big deal with only a few but once you get 30-40 pages it's a noticable difference in both page load times, and server load times  .
__________________
A well-reasoned assumption is very close to fact.
- Adorno
|

09-06-2002, 07:49 PM
|
|
Junior Guru Wannabe
|
|
Join Date: Sep 2002
Location: Brisbane, Australia | The place to be :-)
Posts: 93
|
|
thats a bit of a tedious way of doing it  - it will take up a lot of space
just put:
<?php
include('/your/web/directory/.$page')
?>
then whatever file you put after .../index.php?page= will be included. that way you dont have to modify it whenever u have a new page.
cheers
|

09-07-2002, 06:00 AM
|
|
Disabled
|
|
Join Date: Aug 2002
Posts: 17
|
|
Will that fix the alignment problem?? The alignment problem is still there 
Last edited by BSHbrian; 09-07-2002 at 06:16 AM.
|

09-07-2002, 11:37 AM
|
|
Web Hosting Guru
|
|
Join Date: May 2002
Posts: 344
|
|
I don't see any alignment problems on your page, but either way alignment is controlled with html not php. Something as simple as <center> or <p align="right"> etc would work.
__________________
Chris Miller
PromoPunch
Custom Imprinted Promotional Products
www.promopunch.com 1-800-750-8530 x221
|

09-21-2002, 02:11 AM
|
|
Web Hosting Master
|
|
Join Date: Nov 2000
Posts: 3,042
|
|
I know the thread is a couple of days old but...
Quote:
Originally posted by SpeedFreak
thats a bit of a tedious way of doing it - it will take up a lot of space
just put:
<?php
include('/your/web/directory/.$page')
?>
then whatever file you put after .../index.php?page= will be included. that way you dont have to modify it whenever u have a new page. 
cheers
|
Unless someone screws with the ?page= then you get a crappy file system error. Remember in ANY programming language, you have to create your program to deal with the curious types  .
|

09-21-2002, 05:23 AM
|
|
Web Hosting Master
|
|
Join Date: Jan 2002
Location: Kuwait
Posts: 679
|
|
Quote:
Originally posted by comphosting
I know the thread is a couple of days old but...
Unless someone screws with the ?page= then you get a crappy file system error. Remember in ANY programming language, you have to create your program to deal with the curious types .
|
?page=../../../../../../../../../../../../../../../../../../../etc/.passwd
|

09-21-2002, 05:25 AM
|
|
Web Hosting Master
|
|
Join Date: Jan 2002
Location: Kuwait
Posts: 679
|
|
Quote:
Originally posted by SpeedFreak
thats a bit of a tedious way of doing it - it will take up a lot of space
just put:
<?php
include('/your/web/directory/.$page')
?>
then whatever file you put after .../index.php?page= will be included. that way you dont have to modify it whenever u have a new page. 
cheers
|
This is a security threat, you must do some checking for $page. For example, make sure it only consists of alphanumeric characters.
|

09-21-2002, 08:52 AM
|
|
Disabled
|
|
Join Date: Aug 2002
Posts: 17
|
|
well on the game cheats part of my website, i have 1000's of pages. How can i make it easier for me to load this amount of pages without adding all the coding for every individual page?
|

09-21-2002, 01:53 PM
|
|
Web Hosting Master
|
|
Join Date: Nov 2000
Posts: 3,042
|
|
Here's what I would do (keep in mind that I'm not that great with regular expressions so something might be wrong here):
If for example the url was http://www.domain.com/?page=index
PHP Code:
if (preg_match("/\W/",$page) || !file_exists("/dirtofiles/$page.html")) {
include("/dirtofiles/default.html");
}
else {
include("/dirtofiles/$page.html");
}
Basically what this does is:
The preg_match checks for any "non-word", in otherwords, makes sure there is no character besides letters, numbers and _'s. If it does it simply loads the default page.
If it doesn't then it checks to make sure the file actually exists. If not it loads the default page.
If the previous two ring true (it only contains A-Z, 1-9 and _'s) then it simply includes the file.
[EDIT]
I clicked reply instead of edit  . For whatever reason it's not showing up, but make sure there is a \ BEFORE the W for the regular expression.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
| Postbit Selector |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
| Login: |
|
|
| Advertisement: |
|
|
| Web Hosting News: |
|
|
|