hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : PHP - loading page inside a layout
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

PHP - loading page inside a layout

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 09-05-2002, 08:15 PM
BSHbrian BSHbrian is offline
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!

Reply With Quote


Sponsored Links
  #2  
Old 09-05-2002, 08:20 PM
The Prohacker The Prohacker is offline
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

Reply With Quote
  #3  
Old 09-05-2002, 08:28 PM
BSHbrian BSHbrian is offline
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?

Reply With Quote
Sponsored Links
  #4  
Old 09-05-2002, 08:53 PM
GlideTech GlideTech is offline
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:
Code:
<b>This is a test. This text will show up in index.php if you call it like: http://www.yoursite.com/index.php?page=joinstaff</b>
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

Reply With Quote
  #5  
Old 09-05-2002, 08:56 PM
BSHbrian BSHbrian is offline
Disabled
 
Join Date: Aug 2002
Posts: 17
thanks a lot ! that really helped

Reply With Quote
  #6  
Old 09-05-2002, 09:13 PM
BSHbrian BSHbrian is offline
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

Reply With Quote
  #7  
Old 09-06-2002, 06:18 PM
JustinH JustinH is offline
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


Reply With Quote
  #8  
Old 09-06-2002, 07:49 PM
SpeedFreak SpeedFreak is offline
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

Reply With Quote
  #9  
Old 09-07-2002, 06:00 AM
BSHbrian BSHbrian is offline
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.
Reply With Quote
  #10  
Old 09-07-2002, 11:37 AM
GlideTech GlideTech is offline
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

Reply With Quote
  #11  
Old 09-21-2002, 02:11 AM
JustinH JustinH is offline
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 .

Reply With Quote
  #12  
Old 09-21-2002, 05:23 AM
Ahmad Ahmad is offline
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

__________________
Ahmad Alhashemi
PHP, Apache, C, Python, Perl, SQL
18 related BrainBench certificates

Reply With Quote
  #13  
Old 09-21-2002, 05:25 AM
Ahmad Ahmad is offline
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.

__________________
Ahmad Alhashemi
PHP, Apache, C, Python, Perl, SQL
18 related BrainBench certificates

Reply With Quote
  #14  
Old 09-21-2002, 08:52 AM
BSHbrian BSHbrian is offline
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?

Reply With Quote
  #15  
Old 09-21-2002, 01:53 PM
JustinH JustinH is offline
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.

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
WiredTree Decreases Customer Website Loading Times with SSD Caching Web Hosting News 2013-04-02 13:56:08
1&1 Study Shows 72 Percent of US Online Shoppers Will Abandon Slow Sites for Competitors Web Hosting News 2012-07-13 16:18:05
Certified Hosting Deploys Varnish HTTP Caching for Faster Hosting Services Web Hosting News 2012-02-28 14:10:30
Host Color Offers Free CDN with Shared Web Hosting Web Hosting News 2011-12-19 16:30:09
Google Launches Page Speed CDN Service Web Hosting News 2011-07-28 20:39:17


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?