NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page using includes?

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 02-22-2006, 07:09 AM THREAD STARTER               #1 (permalink)
Senior Member
Join Date: Aug 2005
Location: England
Posts: 1,196
Host47 is a name known to allHost47 is a name known to allHost47 is a name known to allHost47 is a name known to allHost47 is a name known to allHost47 is a name known to all
 



using includes?


I have a website that I have sliced and out to html, then renamed to php (lazy way i know) in the centre i use php include to take the news from the forums and display it in centre of home page...how do i make the buttons do the same, i.e if i click templates a new page opens where the news once was and so on...please don't say iframes my only options...
Host47 is offline  
Old 02-22-2006, 07:37 AM   #2 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




You could do something like this (pretty much what i use, although a little less complicated);

For navigation links:
index.php?page=somepage

Then for the actual including code do something like this

PHP Code:
if (isset($_GET['page']))
{
$includes $_GET['page'];
}

else if (!isset(
$_GET['page']))
{
$includes 'news';
}

include(
$includes '.php'); 
This basically asks if the page in the url is set then use that page, if not then use the news page.
????: NamePros.com http://www.namepros.com/programming/170064-using-includes.html

Hope it helps.
liam_d is offline  
Old 02-22-2006, 07:48 AM THREAD STARTER               #3 (permalink)
Senior Member
Join Date: Aug 2005
Location: England
Posts: 1,196
Host47 is a name known to allHost47 is a name known to allHost47 is a name known to allHost47 is a name known to allHost47 is a name known to allHost47 is a name known to all
 



Quote:
Then for the actual including code do something like this


if (isset($_GET['page']))
{
$includes = $_GET['page'];
}

else if (!isset($_GET['page']))
{
$includes = 'news';
}

include($includes . '.php');

Where do i put the above code, sorry for asking a dumb question, ths is my 1st time .

p.s how much would you charge to do 1 link for me so i can see how it's done....
Host47 is offline  
Old 02-22-2006, 10:44 AM   #4 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




I can do it for free.

Do this;

PHP Code:
<?php
if (isset($_GET['page']))
????: NamePros.com http://www.namepros.com/showthread.php?t=170064
{
$includes $_GET['page'];
}

else if (!isset(
$_GET['page']))
{
$includes 'news';
}

include(
$includes '.php');
?>
Put that code there wherever you want the page to appear.

Assign each link like this (these are examples);
home = index.php?page=home
news = index.php?page=news


Hope that helps.
liam_d is offline  
Old 02-22-2006, 11:13 AM   #5 (permalink)
NamePros Member
Join Date: Feb 2006
Location: Chicago IL
Posts: 73
AllValley is an unknown quantity at this point
 



It's not as good, but you could also do just simple HTML pages for each of the pages, and just put a different include in each page for the content.. But Liam's way is MUCH better. I've been meaning to do this myself for all of my websites... But I'm far too busy.

Rep Added Liam
__________________
Hassle Free Computing and Web Solutions for Personal and Business!
Rochelle Network Communications!
AllValley is offline  
Old 02-22-2006, 11:39 AM   #6 (permalink)
Tech Support
Join Date: Mar 2005
Posts: 4,944
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Using switch(); is another option..
PHP Code:
<?php

//Example link <a href="?page=blah">Blah</a>
$page trim(strip_tags($_GET['page']));

switch(
$page)
{
  case 
'blah':
       include(
"blah.php");
       break;
  case 
'contact':
       include(
"contact.php");
????: NamePros.com http://www.namepros.com/showthread.php?t=170064
       break;
  case 
'links':
       include(
"links.php");
       break;
  default:
       include(
"home.php");
}
?>
Eric is offline  
Old 02-22-2006, 11:55 AM   #7 (permalink)
NamePros Member
Join Date: Feb 2006
Location: Chicago IL
Posts: 73
AllValley is an unknown quantity at this point
 



Which is better? Switch or Liam's code?
__________________
Hassle Free Computing and Web Solutions for Personal and Business!
Rochelle Network Communications!
AllValley is offline  
Old 02-22-2006, 01:10 PM   #8 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




They both work, but switches code makes a tedious task of adding in more pages as you have to add in a new case each time. With mine you don't need to add anything.

And glad i could help
liam_d is offline  
Old 02-22-2006, 01:19 PM   #9 (permalink)
NamePros Regular
 
Jim_'s Avatar
Join Date: Aug 2005
Location: NY, USA
Posts: 608
Jim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to behold
 


Save The Children
With liam's code, however, there is a possibility that someone could do something to the effect of 'http://www.yoursite.com?page=http://www.someonessite.com/theirscript' and execute code on your page.
????: NamePros.com http://www.namepros.com/showthread.php?t=170064

I would suggest either using switch() or using this code insteaed:
Code:
<?php
if(isset($_GET['page']))
  if(file_exists("./pages/" .$_GET['page']. ".php"))
    include("./pages/" .$_GET['page']. ".php");
  else
    include("./pages/404.php");
else
  include("./pages/default.php"); 
?>
__________________
ask me about the internet
Jim_ is offline  
Old 02-22-2006, 01:23 PM   #10 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




Yeah it is always a good idea to make sure you check the pages.

Can also be done with an array, check if the page is an an array of files you set.
liam_d is offline  
Old 02-22-2006, 02:23 PM THREAD STARTER               #11 (permalink)
Senior Member
Join Date: Aug 2005
Location: England
Posts: 1,196
Host47 is a name known to allHost47 is a name known to allHost47 is a name known to allHost47 is a name known to allHost47 is a name known to allHost47 is a name known to all
 



oh man, my head hurts, liam sent me a page with the code but it doesn't work....so i'll reg 2 domains at namecheap to anyone that can add the links to the index.php for me, whilst retianing the main loadpage as the news from the forums...
Host47 is offline  
Old 02-22-2006, 02:43 PM   #12 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




I have told you how to do it, i have done it for you and testing it and it works fine!
liam_d is offline  
Old 02-22-2006, 03:18 PM   #13 (permalink)
Soon to be RICHdoggie!
 
PoorDoggie's Avatar
Join Date: Jan 2005
Location: UK
Posts: 2,408
PoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nicePoorDoggie is just really nice
 



reaper:

Where you have the include already (the one you said you put in, in the very first post) just put in:

PHP Code:
<?php
if(isset($_GET['page'])){
  if(
file_exists("./pages/" .$_GET['page']. ".php")){ // change "pages" to the name of the directory your news page and other stuff is
????: NamePros.com http://www.namepros.com/showthread.php?t=170064
    
include("./pages/" .$_GET['page']. ".php"); // change "pages" again
  
}
  else{
    include(
"./pages/news.php"); // again "pages" and also change "news.php" to the location of the file you were including at the beginning 
  
}
}
else{
  include(
"./pages/news.php"); // again "pages" and also change "news.php" to the location of the file you were including at the beginning
}
?>
... in its place
PoorDoggie is offline  
Old 02-22-2006, 03:52 PM THREAD STARTER               #14 (permalink)
Senior Member
Join Date: Aug 2005
Location: England
Posts: 1,196
Host47 is a name known to allHost47 is a name known to allHost47 is a name known to allHost47 is a name known to allHost47 is a name known to allHost47 is a name known to all
 



all sorted now, liam domais regged and pushed..TR & rep appreciated.

Poordoggie, cheers, rep added anyways....
Host47 is offline  
Old 02-23-2006, 02:05 AM   #15 (permalink)
The original NP Emo Kid
 
liam_d's Avatar
Join Date: Jan 2005
Location: Plymouth, UK
Posts: 1,693
liam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to allliam_d is a name known to all
 




Thanks a lot, glad i could help
liam_d is offline  
Closed Thread


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Includes Albatross Website Development 5 06-14-2005 10:22 AM
259 Domains for Sale (inc. goclassified.com) fle8 Domains For Sale - Make Offer 0 05-02-2004 08:57 AM
HOWEIRDDEAN.COM includes website, plus 2 free doamins! interneta Domains For Sale - Make Offer 6 02-17-2004 02:12 PM

 
All times are GMT -7. The time now is 02:09 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger