Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 804 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

PHP Page includes..

Thread title: PHP Page includes..
Closed Thread  
Page 1 of 3 1 2 3 >
    Thread tools Search this thread Display Modes  
01-12-2006, 01:23 AM
#1
blindchild02 is offline blindchild02
blindchild02's Avatar
Status: TF Veteran
Join date: Jan 2005
Location:
Expertise:
Software:
 
Posts: 3,258
iTrader: 2 / 100%
 

blindchild02 is on a distinguished road

  Old  PHP Page includes..

What is the best way to go about PHP Page includes?

such as, clicking a link, and loading a page into the spot where you place the PHP....

without the use of ?view=page (for the link)

01-12-2006, 02:09 AM
#2
bluearctic is offline bluearctic
bluearctic's Avatar
Status: Junior Member
Join date: Dec 2005
Location:
Expertise:
Software:
 
Posts: 66
iTrader: 0 / 0%
 

bluearctic is on a distinguished road

  Old

Blind,
What are you trying to do? If you want simple php includes for your footer tag(text links, copyright), or for your menu, header, ect.. You can name all your .html files to .php and include this simple code on every one of your pages which would allow you to edit 1 file and it would update your entire sites footer.
PHP Code:
<? include("page_name_here"?>
If this is not the case please explain yourself better and I'll try helping.

01-12-2006, 02:16 AM
#3
blindchild02 is offline blindchild02
blindchild02's Avatar
Status: TF Veteran
Join date: Jan 2005
Location:
Expertise:
Software:
 
Posts: 3,258
iTrader: 2 / 100%
 

blindchild02 is on a distinguished road

  Old

i know how to do includes like that...

what im looking to do..

is be able to click a link (say in the header or something...)
and when i click the link, it opens say page... contact.php,
but it opens the page where i insert the php to view the page,
sorta like an iframe... but using includes

01-12-2006, 02:25 AM
#4
bluearctic is offline bluearctic
bluearctic's Avatar
Status: Junior Member
Join date: Dec 2005
Location:
Expertise:
Software:
 
Posts: 66
iTrader: 0 / 0%
 

bluearctic is on a distinguished road

  Old

so.. you want php to load like an iframe (content only) without loading your whole site over again (graphics and menu) but using php? Correct?

01-12-2006, 02:29 AM
#5
bluearctic is offline bluearctic
bluearctic's Avatar
Status: Junior Member
Join date: Dec 2005
Location:
Expertise:
Software:
 
Posts: 66
iTrader: 0 / 0%
 

bluearctic is on a distinguished road

  Old

check this out.. let me know if I'm on the right track.

http://www.devx.com/webdev/Article/28456/1954?pf=true

01-12-2006, 02:52 AM
#6
blindchild02 is offline blindchild02
blindchild02's Avatar
Status: TF Veteran
Join date: Jan 2005
Location:
Expertise:
Software:
 
Posts: 3,258
iTrader: 2 / 100%
 

blindchild02 is on a distinguished road

  Old

well, it doesnt matter if the page reloads.... its ok if it does,
and that page seems like alot of work, haha

01-12-2006, 03:19 AM
#7
Nirvana- is offline Nirvana-
Status: Member
Join date: Sep 2005
Location: United States
Expertise:
Software:
 
Posts: 286
iTrader: 0 / 0%
 

Nirvana- is on a distinguished road

  Old

Ok, there are two ways you can use to approach this... Depending on the flexibility that you need, as in new variables and such..
The first way, is more secure, but you also need to define each page as well.
PHP Code:
<?php
switch($id)
{
  default:
    include(
'index.html');
  break;
  case 
"page1":
    include(
'page1.html');
  break;
  case 
"page2":
    include(
'page2.html');
  break;
  case 
"page3":
    include(
'page3.html');
  break;
  case 
"page4":
    include(
'page4.html');
  break;
  case 
"page5":
    include(
'page5.html');
}
?>
your url would be index.php?id=page2 etc. and it would load the "page2.html" inside the content area where you have the include...

the other way, although less secure, is much more flexible...
PHP Code:
<?php
$_GET
["id"] = str_replace("..","",$_GET["id"]);
$val $_GET['id'];
$val .= ".php";
if (isset(
$_GET['id']))
{
  if (
file_exists($val))
  {
    include 
"$val";
  }
  else
  {
    include 
"404.php";
  }
}
else
{
  include 
"defaultpage.php";
}
?>
Ok, this one is a bit more complex, it will get the id that was loaded in the browser... if there isnt one set, it will load defaultpage.php, if it was set, it checks if it exists, then loads it. if it doesnt exist, it simply loads 404.php..

Hope that helps you

01-12-2006, 04:09 AM
#8
blindchild02 is offline blindchild02
blindchild02's Avatar
Status: TF Veteran
Join date: Jan 2005
Location:
Expertise:
Software:
 
Posts: 3,258
iTrader: 2 / 100%
 

blindchild02 is on a distinguished road

  Old

ok... hm... how do i do that first one?

01-12-2006, 04:13 AM
#9
iisbum is offline iisbum
iisbum's Avatar
Status: Member
Join date: Oct 2005
Location: Clifton Park, NY, USA
Expertise:
Software:
 
Posts: 273
iTrader: 4 / 100%
 

iisbum is on a distinguished road

  Old

URL rewriting is one way to go. This allows you to turn:

http://site.com/pages/about_us.php
into
http://site.com/index.php?page=about_us

this is done invisibly to the site visitor.

your script would still work in the same way, including the appropriate file, but the URL would look very nice to search engines.

HTH,
Mubs

01-12-2006, 04:41 AM
#10
sletts02 is offline sletts02
sletts02's Avatar
Status: Online
Join date: Nov 2005
Location: Brisbane, Auustraaaliiaaaa
Expertise:
Software:
 
Posts: 1,279
iTrader: 0 / 0%
 

sletts02 is on a distinguished road

Send a message via MSN to sletts02

  Old

For the fist one posted by nirvana you simply enter the following code where you want your included page to go.

PHP Code:
<?php
switch($id)
{
  default:
    include(
'index.html');
  break;
  case 
"websites":
    include(
'websites.html');
  break;
  case 
"logos":
    include(
'logodesigns.html');
  break;
  case 
"smallurl":
    include(
'however_large_long_page_name.html');
  break;
  case 
"page4":
    include(
'page4.html');
  break;
  case 
"page5":
    include(
'page5.html');
}
?>
Instead of doing this for your links:
HTML Code:
<a href="websites.php"></a>

<!-- You enter THIS code instead... -->
<a href="index.php?id=websites"></a>

<!-- This is especially good when you have a long page name like in the small url example. -->

Original Link:
<a href="however_large_long_page_name.html"></a>

It would Be:
<a href="index.php?id=smallurl"></a>

Closed Thread  
Page 1 of 3 1 2 3 >


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed