Author Topic: Including a page within another page  (Read 1940 times)

Offline Zeggy

  • Global Moderator
  • Level 35
  • *****
  • Posts: 1,187
  • Reputation: +13/-4
    • View Profile
Including a page within another page
« on: October 30, 2006, 12:07:22 PM »
This is a simple function to include a seperate page within another page:

Code: [Select]
<?php
include("path or url here");
?>

It's pretty straightforward.
It can be used for many functions, such as:
including a settings/config page
including a page from another website... makes for nice dynamic content :P

Offline Mgccl

  • Level 7
  • *
  • Posts: 33
  • Reputation: +1/-0
    • View Profile
    • WebDevLogs
Re: Including a page within another page
« Reply #1 on: November 09, 2006, 10:48:41 PM »
say.. here is something about include...
Include is slower than some other functions...
so if you just want to output some raw HTML(no PHP inside.. like some template)
try use this function
Code: [Select]
<?php
include($filename); //contain PHP code in it
readfile($filename); //raw outputs.. no PHP inside...
?>

readfile will be much faster and use less ram especially when the FILE is HUGE(supose... 32 MB)

Offline Karlos

  • Level 7
  • *
  • Posts: 31
  • Reputation: +2/-0
    • View Profile
Re: Including a page within another page
« Reply #2 on: March 08, 2009, 11:04:01 AM »
Why not mention require()? require_once() or even include_once()?  :-\

Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
Re: Including a page within another page
« Reply #3 on: March 08, 2009, 02:25:33 PM »
I guess we could add also (beside other facts)

- about how to deal with it's argument, as it's not so straightforward: without prefix ./ or ../ it's not the directory of script, where php searches first, but in include_path, which is path defined in the php's options and when unsuccessful, then the engine searches in the directory of the current script (so be careful not to include different file than you wanted)

- in the file you include all the variables from before including are also avalible in the included script, all functiones and classes from a included file have global scope

- using include construct is not http request, so no absolute http://, no GET attributes in url

- about including either content to center or top and bottom part (I prefer this way) of page when constructing a dynamic webpage
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline ckumarjha

  • Level 7
  • *
  • Posts: 28
  • Reputation: +0/-0
    • View Profile
Re: Including a page within another page
« Reply #4 on: August 06, 2009, 03:52:14 PM »
I guess we could add also (beside other facts)

- about how to deal with it's argument, as it's not so straightforward: without prefix ./ or ../ it's not the directory of script, where php searches first, but in include_path, which is path defined in the php's options and when unsuccessful, then the engine searches in the directory of the current script (so be careful not to include different file than you wanted)

- in the file you include all the variables from before including are also avalible in the included script, all functiones and classes from a included file have global scope

- using include construct is not http request, so no absolute http://, no GET attributes in url

- about including either content to center or top and bottom part (I prefer this way) of page when constructing a dynamic webpage

i have started php a few days back and did not read about this any where...... thnx you saved me from making big mistakes.....

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal