Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with includes required

Status
Not open for further replies.

hpicken

Technical User
Apr 12, 2001
142
0
0
AU
I'm setting up a simple template type site and I was wondering why this doesn't work

...
if (isset($_GET['sc'])) {
include($fullpath . 'bookshop.php?sc=1&cat='.$_GET['cat']);
} else {
...

I've also tried

...
$tmppath = $fullpath . 'bookshop.php?sc=1&cat='.$_GET['cat'];
include($tmpath);
...

Is there a work around this?

Howard
 
Are you including http:// in $fullpath? See example 16-7 in the php manual.
 
Yep!

fullpath is fullu qualified url,
I have other includes and they work ok but I'm not passing data with the url on them.

H
 
Does $fullpath end with a slash (/)? If not, the result will be something like which is probably not what you want.

Your best bet is to follow DaButcher's suggestion and use echo to see the exact result of the concatenated string.
 
Is it necessary that you get the page using a HTTP request?
Can't you just include the code itself over the much faster file system and execute it within the script?

Each page here will have an additional request to the web server because of the http://
You own all the scripts, and to keep your site really 'simple' I would recommend to review the structure and eliminate the http:// since it creates unnecessary overhead.
 
Including over internet (http) only works when the fopen wrappers are enabled in php (see and like DRJ478 says you should not use http unless really nessecary.

Btw if including files you don't pass those files parameters in the url like you do. Include takes place before parsing the page, and the variables available in the mainscript will also be available in the included file.

If you don't like to have all variables global, write your functionality in bookshop.php in a function and call that function with the parameters after including the file.
 
Thanks guys. I've been away for most of the week so I haven't been able to respond. I'll have a look at it and your replies over the weekend in more detail.

Howard
 
Fixed!

I had allow_url_fopen turned on but through some slack coding (which I've cleaned up) I was referencing the full unix path, not the full url (duh!).

DRJ478, the reason I'm doing it this way is so my wife who is OK with html not php can edit the html parts of the site without worrying about the rest of it. I'll eventually put up a web based html editor for her use.

Thanks again folks.

Howard
 
If you have a structure like this:
domain.tld/folder1/folder2/folder3

your index is in folder2.
To include in folder1: include("/folder1/foo.php");
To include in folder2: include("bar.php");
To include in folder3: include("folder3/omg.php");

If you are in folder3, and want to include in folder2:
include("../

I guess you get the idea..
starts with / => from doc_root
starts with foldername/ => subfolder from current folder
starts with ../ => parent of current folder
only filename => current folder

Olav Alexander Mjelde
Admin & Webmaster
 
I've been using full HTML templates for years and never come across the need to include them using a HTTP request.
Maybe a look at the PEAR template class can help you ease the maintenance.
We are here in a multi-departmental setting where HTML and code are strictly separated, for exactly the same reasons you name. All templates are edited using a commercial HTML product from Macromedia. No confusion!
 
Once again thanks everybody for your replies. I have everything going as I want but, yes DRJ478, PEAR templates is something I want to look at later when the site needs to grow again.

I'm still learning and have learnt a lot from this little exercise. I've cut 30+ pages down to 4 so I'm happy with my efforts so far.

Anyway... have a great Xmas and a brilliant new year guys.

Cheers
Howard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top