Welcome to Dream.In.Code
Become a PHP Expert!

Join 136,896 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,722 people online right now. Registration is fast and FREE... Join Now!




Embed a different web page using PHP

 
Reply to this topicStart new topic

Embed a different web page using PHP

theholygod
24 Mar, 2008 - 12:16 PM
Post #1

D.I.C Head
**

Joined: 5 Feb, 2006
Posts: 215


My Contributions
Hi

I've used inline frames a lot before, but they have loads of downsides. I'm looking to achieve the same effect using PHP.

I pretty much want my website set up so there is only one page that has the site layout, pages of information would then be pasted into that layout when hyperlinks are clicked. I imagine i would go about having my web pages created in such a way that they call upon the html of the layout page and then places the current information into a specific portion of that web page.

Example:
www.mywebsite.com = www.mywebsite.com/layout.html + www.mywebsite.com/index.php

Can anyone give me pointers of where to start with this?
User is offlineProfile CardPM
+Quote Post

grimpirate
RE: Embed A Different Web Page Using PHP
24 Mar, 2008 - 12:26 PM
Post #2

D.I.C Head
Group Icon

Joined: 3 Aug, 2006
Posts: 192



Thanked: 5 times
Dream Kudos: 375
My Contributions
In order to do this, the easiest way would be use the $_GET superglobal array. Basically at the end of your www.mywebsite.com URL you would append ?id=something. Then your code would do the following:
CODE
switch($_GET['id']){
case 0:
...
break;
case 1:
...
break;
case ...:
break;
default:
// throw some sort of 404 error because that page is nonexistent
break;
}


This post has been edited by grimpirate: 24 Mar, 2008 - 12:26 PM
User is online!Profile CardPM
+Quote Post

theholygod
RE: Embed A Different Web Page Using PHP
24 Mar, 2008 - 12:30 PM
Post #3

D.I.C Head
**

Joined: 5 Feb, 2006
Posts: 215


My Contributions
So there would be 1 page that stores every page?
User is offlineProfile CardPM
+Quote Post

c0mrade
RE: Embed A Different Web Page Using PHP
24 Mar, 2008 - 12:59 PM
Post #4

D.I.C Head
**

Joined: 16 Nov, 2007
Posts: 111



Thanked: 1 times
My Contributions
Take a look at Smarty. www.smarty.net - smarty is a php template system

Also, you could consider a heavier fully fledged CMS's like Joomla (www.joomla.org) or Drupal (www.drupal.org).

Another option is using a php framework which uses a M-V-C architecture. Some common ones are CakePHP, Symfony, Codeigniter, and (if you're up for a challange) Zend Framework.

Smarty might be the best for you. The frameworks take some time to learn - and the big CMS's can be limiting.
User is offlineProfile CardPM
+Quote Post

spearfish
RE: Embed A Different Web Page Using PHP
24 Mar, 2008 - 02:43 PM
Post #5

Monkey in Training
Group Icon

Joined: 10 Mar, 2008
Posts: 746



Thanked: 2 times
Dream Kudos: 225
My Contributions
Essentially, yes, that one page would store every other page. But what you could do with the switch statement would be to have
CODE

case 1:
include("page1.php");
break;


So that index.php or whatever doesn't store all of the pages in it, rather it just includes whatever page the user is trying to get at.

An even better way to do it would be:

CODE

include("page{$_GET['id']}.php";


Where the page with an ID of 0 is page0.php.
User is offlineProfile CardPM
+Quote Post

theholygod
RE: Embed A Different Web Page Using PHP
24 Mar, 2008 - 03:36 PM
Post #6

D.I.C Head
**

Joined: 5 Feb, 2006
Posts: 215


My Contributions
Thanks spearfish, that sounds like the ideal solution.

Comrade, i looked at smarty and it seems completely above me, thanks anyway.

Getting late here and I'm tired, so I'll try this stuff out tomorrow morning. Thanks loads guys.
User is offlineProfile CardPM
+Quote Post

spearfish
RE: Embed A Different Web Page Using PHP
24 Mar, 2008 - 04:02 PM
Post #7

Monkey in Training
Group Icon

Joined: 10 Mar, 2008
Posts: 746



Thanked: 2 times
Dream Kudos: 225
My Contributions
Not a problem. Glad I can help somebody with more than a half dozen posts wink2.gif
User is offlineProfile CardPM
+Quote Post

theholygod
RE: Embed A Different Web Page Using PHP
25 Mar, 2008 - 10:48 AM
Post #8

D.I.C Head
**

Joined: 5 Feb, 2006
Posts: 215


My Contributions
Ok, this is what i have so far:

CODE

    if(isset($_GET['id']))
    {
        include("{$_GET['id']}.php");
    }
    else
    {
        include("main.php");
    }


This is working brilliantly for me. How would i go about checking to see if a page exists?
User is offlineProfile CardPM
+Quote Post

spearfish
RE: Embed A Different Web Page Using PHP
25 Mar, 2008 - 11:05 AM
Post #9

Monkey in Training
Group Icon

Joined: 10 Mar, 2008
Posts: 746



Thanked: 2 times
Dream Kudos: 225
My Contributions
Using the file_exists function.

CODE


if(isset($_GET['id')) {
     if (file_exists($_GET['id'])) {
          include("{$_GET['id']}.php");
          }
     }


Sorry if my syntax is off on the file_exists function, I've never used it before.
User is offlineProfile CardPM
+Quote Post

theholygod
RE: Embed A Different Web Page Using PHP
26 Mar, 2008 - 02:28 AM
Post #10

D.I.C Head
**

Joined: 5 Feb, 2006
Posts: 215


My Contributions
That's working really well for me, thanks spearfish. I wish i had known this stuff a few years ago, would have saved me a lot of time.

CODE

if(isset($_GET['id']))
    {
        if (file_exists($_GET['id']))
        {
            include("{$_GET['id']}.php");
        }
        else
        {
            include("custom404.php");
        }
    }    
    else
    {
        include("main.php");
    }        


This post has been edited by theholygod: 26 Mar, 2008 - 02:29 AM
User is offlineProfile CardPM
+Quote Post

spearfish
RE: Embed A Different Web Page Using PHP
26 Mar, 2008 - 05:29 AM
Post #11

Monkey in Training
Group Icon

Joined: 10 Mar, 2008
Posts: 746



Thanked: 2 times
Dream Kudos: 225
My Contributions
Don't worry about it - I just remembered what functions are. Doi! I have a 300 line program that probably could be narrowed down to 175 with functions.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 09:27PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month