Old 12-03-2007, 17:35   #1 (permalink)
pat
jorge regula
 
pat's Avatar
 
Join Date: Aug 2004
Location: B'ham/Leeds
Posts: 4,860
Send a message via MSN to pat
php include

cobbled together this snippet:
Code:
<? if(!$page) { include("home.php"); } else{ include("/" . "$page" . ".php"); } ?>

Put it in index.php, idea being that if no links are clicked, the page displays home.php where this code is palced.

If a link is clicked, it's sposed to load that page, but it doesn't!

My links look like index.php?page=background

any ideas?
__________________
  Reply With Quote
Old 12-03-2007, 18:04   #2 (permalink)
d3mcfadden
Senior Member
 
d3mcfadden's Avatar
 
Join Date: Apr 2005
Location: -
Posts: 694
Send a message via AIM to d3mcfadden
have you defined $page?
eg.
PHP Code:
$page = isset ($_GET['page']) ? $_GET['page'] : "home"
most likely reg globals are off (as they should be) so you will have to define $page. This will eliminate the need for that if statement too because above we default it to "home" if none is supplied.

now just:
PHP Code:
include("/" $page ".php"); 
  Reply With Quote
Old 12-03-2007, 18:45   #3 (permalink)
EGONick
Programmer
 
EGONick's Avatar
 
Join Date: Jan 2007
Location: UK, Manchester
Posts: 36
PHP Code:
<?php
if($_REQUEST['page'])
{
    if(
file_exists($_REQUEST['page'] . '.php'))
    {
        include(
$_REQUEST['page'] . '.php');
    }
    else
    {
        include(
'home.php');
    }
}
else
{
    include(
'home.php');
}
?>

Always check if the file exists.
  Reply With Quote
Old 13-03-2007, 09:38   #4 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 4,962
Are you sorted with this now pat.

Liking that code EGONick. (borrows)

I think the / was messing you up pat.
__________________
  Reply With Quote
Old 13-03-2007, 09:56   #5 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 4,962
Here's another trick Pat. (which I have mentioned before)

say you want to include a page stuff.htm.

the url index.php?page=stuff is not very SEO or user friendly.

So create another page stuff.php with the content

Code:
<?php $page = "stuff"; include("index.php"); ?>
__________________
  Reply With Quote
Old 13-03-2007, 10:16   #6 (permalink)
pat
jorge regula
 
pat's Avatar
 
Join Date: Aug 2004
Location: B'ham/Leeds
Posts: 4,860
Send a message via MSN to pat
Thanks very much all, very helpful. I'm not overly worried about SEO but I'll see about adding that in DH.
__________________
  Reply With Quote
Old 13-03-2007, 10:18   #7 (permalink)
pgo
Senior Member
 
Join Date: Jan 2005
Posts: 12,340
Or you could rewrite "index.php?page=stuff" as "/stuff/" which would be better in the long run anyway, I think.
  Reply With Quote
Reply



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

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8