navigation
a webmaster learning community
     Home    Register     Search      Help      Login    
Sponsors

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions.

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

 

Dynamic php includes script

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Community >> OutFront Discoveries >> Dynamic php includes script
Page: [1]
 
womble

 

Posts: 5702
Joined: 3/14/2005
From: Living on the edge
Status: offline

 
Dynamic php includes script - 2/3/2006 6:34:21   
A nice little script for switching php includes that you could use for site navigation, glossaries, FAQs etc. Because it's server-side php there's no worries about javascipt being switched off or anything, accessible because you're just using normal hyperlinks to switch between includes (I think the dynamic bit would probably be okay with screenreaders but as Fangs for FF isn't yet updated for FF1.5 I haven't been able to check that out), and valid (as long as the code in your include's valid ;)), just a few lines of php, so you can use it with any flavour of html/xhtml.

http://www.jh-designs.com/?id=tutorials&page=comment&oid=34

_____________________________

~~ "A cruel god ain't no god at all" ~~
~~ Erase hate. Practice love. ~~
:)
Kitka

 

Posts: 2520
Joined: 1/31/2002
From: Australia
Status: offline

 
RE: Dynamic php includes script - 2/3/2006 18:03:25   
Ooo, very nice find womble! I was about to go looking for this exact thing for a site I have in the planning stages. You saved me the trouble. :)

/hands womble a big bag of minstrels :)

_____________________________

Kitka
**It is impossible to make anything foolproof because fools are so ingenious.**


(in reply to womble)
womble

 

Posts: 5702
Joined: 3/14/2005
From: Living on the edge
Status: offline

 
RE: Dynamic php includes script - 2/3/2006 18:39:17   
Yum! Womble likes Minstrels! :)

/adds Kitka to xmas card list :)

Only problem I had with it was that I had to use absolute urls - it didn't like the relative ones - but it's working like a dream now! :)

_____________________________

~~ "A cruel god ain't no god at all" ~~
~~ Erase hate. Practice love. ~~
:)

(in reply to Kitka)
womble

 

Posts: 5702
Joined: 3/14/2005
From: Living on the edge
Status: offline

 
RE: Dynamic php includes script - 10/13/2006 19:03:13   
UPDATE: I recently had a PM from Kitka asking if I had the code for this type of PHP include, as it appears that the original link I posted is no longer there. I've since found partically the same tutorial here, and reminded of just how easy it is to use, working on a site at the moment and I decided to use the same method on a page. <grin> No problems, done it once, piece of cake - no problems!

Easy, yes? Erm, no.... :) :)

It took me two hours to figure out why exactly the same syntax wasn't working! Two hours of changing single quotes to double quotes, moving semi-colons, then moving them back because though my knowledge of PHP isn't great, I *knew* they were in the right place. The syntax was identical - I even copied the original page from the previous site I'd used it on, onto the server where the site currently under construction resides. Works on the original site...not the new one. Two hours I've been messing around with it!

Then I dimly recalled an email from the hosts of the currently under construction site, something about "register_globals" I seemed to recall - so I dug it out and had a look, and off a-googling again I went, and eventually after much muttering obcenities at the screen, found this thread at CSS Creator.

The syntax of creating a dynamic PHP is easy - you need links to be able to click to change the content, and case/breaks to change the content when the link is clicked...:
<p class="glosslink"><a href="glossary.php?id=glossary_a">A</a> ◊ <a href="glossary.php?id=glossary_b">B</a> ◊ <a href="glossary.php?id=glossary_c">C</a> ◊
		<a href="glossary.php?id=glossary_d">D</a> ◊ <a href="glossary.php?id=glossary_e">E</a></p>
			
		<?php switch($id) { default: include('http://www.mydomain.com/includes/gloss_default.php');
		break; case "glossary_a": include('http://www.mydomain.com/includes/glossary_a.php');
		break; case "glossary_b": include('http://www.mydomain.com/includes/glossary_b.php');
		break; case "glossary_c": include('http://www.mydomain.com/includes/glossary_c.php');
		break; case "glossary_d": include('http://www.mydomain.com/includes/glossary_d.php');
		break; case "glossary_e": include('http://www.mydomain.com/includes/glossary_e.php');

Two points for anyone that wants to try this and is running on a server with register_globals off, that these articles don't tell you, is that if register_globals are switched off on your domain,
- you need to add this after the PHP tag but before the switch statement
$id = $_GET["id"];

- you need to use double quotes throughout, rather than single quotes, so:
<?php $id = $_GET["id"];
                switch($id) { default: include("http://www.mydomain.com/includes/gloss_default.php");
		break; case "glossary_a": include("http://www.mydomain.com/includes/glossary_a.php");
		break; case "glossary_b": include("http://www.mydomain.com/includes/glossary_b.php");
		break; case "glossary_c": include("http://www.mydomain.com/includes/glossary_c.php");
		break; case "glossary_d": include("http://www.mydomain.com/includes/glossary_d.php");
		break; case "glossary_e": include("http://www.mydomain.com/includes/glossary_e.php");


Hopefully that might be of some use to anyone who decides to try dynamic includes but can't get them to work, or has includes that have suddenly stopped functioning.

I know all this global_registers malarky is all in the name of security - but just grrrr!!!!! :) :)

_____________________________

~~ "A cruel god ain't no god at all" ~~
~~ Erase hate. Practice love. ~~
:)

(in reply to womble)
Kitka

 

Posts: 2520
Joined: 1/31/2002
From: Australia
Status: offline

 
RE: Dynamic php includes script - 10/13/2006 19:14:26   
Oops!

I was going to post an update here myself, as I ran into that very same problem. :)

But I hadn't got around to it yet, as I am totally snowed under with work, and didn't realise anyone else would be referring to this thread so soon.

I spent almost a whole day trying to figure out why it wasn't functioning, until I hit on the bright idea of trying it on a different server. It worked <whew> so then I asked the hosts for the site I was needing to use the code on for support and finally found out about register_globals <argh!>.

Very sorry Womble - I could have prevented your pain.

/ offers a bag of Minstrels in penance :)

_____________________________

Kitka
**It is impossible to make anything foolproof because fools are so ingenious.**


(in reply to womble)
womble

 

Posts: 5702
Joined: 3/14/2005
From: Living on the edge
Status: offline

 
RE: Dynamic php includes script - 10/13/2006 19:25:09   
:) :)
It's okay Kitka, I've been snowed under myself, hence me only just having got round to using it again. With me it was trying the page from the other site on the new domain that did it. It's a live site and it's working perfectly well, so when exactly the same page wouldn't work on the other server, I knew it had to be something different between the two servers. Strangely the other day I did think about checking out the support forums for the forums I run on the affected domains in case anything would be stopping working on them - it never even ocurred to me that anything else might be affected!

/happily munches Minstrels :)

_____________________________

~~ "A cruel god ain't no god at all" ~~
~~ Erase hate. Practice love. ~~
:)

(in reply to Kitka)
Kitka

 

Posts: 2520
Joined: 1/31/2002
From: Australia
Status: offline

 
RE: Dynamic php includes script - 10/13/2006 19:31:11   
A couple of technical details:

quote:

I had to use absolute urls


I have it functioning nicely with relative URLs, so test to see which works best for you/your server.

quote:

- you need to use double quotes throughout, rather than single quotes, so:


I have used double quotes everywhere except in the following part of the code, and it works well.

case "file": include('incl/file.php');


_____________________________

Kitka
**It is impossible to make anything foolproof because fools are so ingenious.**


(in reply to Kitka)
BobbyDouglas

 

Posts: 5470
Joined: 5/15/2003
From: Arizona
Status: offline

 
RE: Dynamic php includes script - 10/13/2006 20:14:50   
quote:

Only problem I had with it was that I had to use absolute urls - it didn't like the relative ones

- Are you sure the relative path was correct? I don't understand why PHP wouldn't be able to include something using a relative URL? Lots of php scripts use relative URLs for includes. If you don't specify the full location to the php file, then every script you use will be using a relative link for the include.

Here's how I use includes and such for navigation type pages:

For the Service page:
<?php $page="Service"; include("main-navigation.php"); ?>


and then in my main-navigation.php page I have:
        <li><a href="/Service-Department/">Service Department</a><?php if ( $page=="Service" ) {echo '
		  <ul id="subnavlist">
			<li class="both"><a href="/Service-Department/Submit-Service-Request/">Submit Service Request</a></li>
		  </ul>';} ?>
		</li>


So if the page you are on is part of the service dept., then it will show the submenu of Service Department on the navigation area.

I also use this type of include for the title/head sections of pages:

So for index.php >
<?php $page_title="Website Name - Home"; include("header.php"); ?>


and then header.php >
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" >
<head>
<title><?php echo $page_title; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/scripts/address.js"></script>
<?php if($page_title=="This script should only load for a specific page") { echo
'<script type="text/javascript" src="/scripts/lightbox.js"></script>
<link href="/lightbox.css" rel="stylesheet" type="text/css" />';} ?>
</head>


Notice that not every page loads the lightbox script.

quote:

you need to use double quotes throughout, rather than single quotes, so:

- You can use double or single quotes. I tend to use single quotes when working with HTML, reason being is that if you use a double quote, you will have to place a \ behind every double quote that appears in your HTML code.

<?php if($some_var) { echo "<h1 class=\"h1_norm\">";} ?> Echos <h1 class="h1_norm">
<?php if($some_var) { echo "<h1 class='h1_norm'>";} ?> Echos <h1 class='h1_norm'>
<?php if($some_var) { echo '<h1 class="h1_norm">';} ?> Echos <h1 class="h1_norm">
<?php if($some_var) { echo '<h1 class=\"h1_norm\">';} ?> Echos <h1 class="h1_norm">
<?php if($some_var) { echo "<h1 class="h1_norm">";} ?> Gives error

< Message edited by BobbyDouglas -- 10/13/2006 20:20:11 >


_____________________________

Arizona Web Design - Mr Bobs Web Design in Arizona
The Arizona Web Hosting Challenge

(in reply to Kitka)
treetopsranch

 

Posts: 1141
From: Cottage Grove, OR, USA
Status: offline

 
RE: Dynamic php includes script - 10/13/2006 22:52:30   
wombie, that link doesn't seem to be working now.

_____________________________

Don from TreeTops Ranch, Oregon

"I've got a taste for quality and luxury"


(in reply to BobbyDouglas)
Kitka

 

Posts: 2520
Joined: 1/31/2002
From: Australia
Status: offline

 
RE: Dynamic php includes script - 10/13/2006 23:01:37   
Hi Don,

Do you mean the link in Womble's first post, or the one in post #4?

We already know that #1 isn't working but this link in post #4 works for me right now:

http://www.digital-web.com/articles/easypeasy_php

_____________________________

Kitka
**It is impossible to make anything foolproof because fools are so ingenious.**


(in reply to treetopsranch)
jaybee

 

Posts: 14191
Joined: 10/7/2003
From: Berkshire, UK
Status: offline

 
RE: Dynamic php includes script - 10/14/2006 5:51:03   
Re register_globals off.....

PHP now ships with them off for security reasons. Many hosts will not turn them back on even if you ask them to. If you are writing PHP code you need to use GET and POST, if you are going for a legacy piece of open source code, check to see that it works with globals off. If it doesn't specify then ask the author, if you can't then have a look through the code for GET and POST. If they're not there then you need globals on or you'll have to rewrite those bits.

Wombly, as for relative urls and php, I've had problems with them in the past. It's usually down to the path set up on your host and you need to experiment. One host I can get away with pretty much what I'd do in the html, the other I have to specify it right from home/domain/public_html/.....

_____________________________

If it ain't broke..... fix it until it is.
:)

:)
GAWDS
Now where did I put that Doctype?

(in reply to Kitka)
womble

 

Posts: 5702
Joined: 3/14/2005
From: Living on the edge
Status: offline

 
RE: Dynamic php includes script - 10/14/2006 17:40:35   
:)

_____________________________

~~ "A cruel god ain't no god at all" ~~
~~ Erase hate. Practice love. ~~
:)

(in reply to jaybee)
Page:   [1]

All Forums >> Community >> OutFront Discoveries >> Dynamic php includes script
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts