Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > PHP Problem...

PHP Problem...
Thread Tools
Addicted to MacNN
Join Date: Oct 2002
Location: England | San Francisco
Status: Offline
Reply With Quote
Jun 14, 2004, 02:38 PM
 
I am having an error on my site (hejog.net). I am building a site which gathers my blog from /blog/index.php - I've used a php include like so -
<?php include ("/blog/index.php"); ?>
but it cannot find the file...
Dont suppose anyone knows whats wrong, I've never really used php
we don't have time to stop for gas
     
Clinically Insane
Join Date: Nov 1999
Status: Offline
Reply With Quote
Jun 14, 2004, 02:51 PM
 
PHP's include system doesn't use relative URLs; you need to tell it where the file is on disk. You can make PHP understand absolute URLs in the include function, but I don't recommend it; the potential security issues are more trouble than it's worth.
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
     
Peter  (op)
Addicted to MacNN
Join Date: Oct 2002
Location: England | San Francisco
Status: Offline
Reply With Quote
Jun 14, 2004, 03:43 PM
 
still doesnt work
we don't have time to stop for gas
     
Occasionally Useful
Join Date: Jun 2001
Location: Liverpool, UK
Status: Offline
Reply With Quote
Jun 14, 2004, 03:48 PM
 
do something like this: [php]$blogPath = "/full/path/to/blog/dir";
$blogPage = "index.php";
$blog = "$blogPath/$blogPage";
include $blog; [/php] this way, it's easier to change the paths if you test on a different server than the working script ends up on, or if you rename the script.
"Have sharp knives. Be creative. Cook to music" ~ maxelson
     
Peter  (op)
Addicted to MacNN
Join Date: Oct 2002
Location: England | San Francisco
Status: Offline
Reply With Quote
Jun 14, 2004, 04:07 PM
 
okay, I am using an iframe until i get around to changing that bit, but... the alignment of the iframe text seems to stick it to one side, I dont see an option to change where the text wraps to the next line in the css :/
we don't have time to stop for gas
     
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Jun 14, 2004, 04:23 PM
 
Not too sure what you mean, but text-align: right; will put the text to the right. Althoguh, be careful (i.e. read the w3c specs as to what elements this will work on - there's some discrepencies, but, generally, text within a div is fine for aligning).

Or, just chuck it all in a <center> tag if you want it to go in the middle...
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
Peter  (op)
Addicted to MacNN
Join Date: Oct 2002
Location: England | San Francisco
Status: Offline
Reply With Quote
Jun 14, 2004, 04:27 PM
 
I am not sure whats causing the text of the 'blog' to stick to the left hand side of the website.
we don't have time to stop for gas
     
Occasionally Useful
Join Date: Jun 2001
Location: Liverpool, UK
Status: Offline
Reply With Quote
Jun 14, 2004, 06:12 PM
 
stone the flamin' crows, ya flamin' galah. provide us with a working URL to check out, Peter, before Mundy turns into Alf Stewart again!
"Have sharp knives. Be creative. Cook to music" ~ maxelson
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Jun 15, 2004, 04:48 AM
 
Use PHP to calculate the Path for you:

[php]

$link_url = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" . "page2.php";


[/php]
     
Senior User
Join Date: Jan 2000
Location: Burlington, VT, USA
Status: Offline
Reply With Quote
Jun 15, 2004, 09:30 AM
 
Originally posted by Diggory Laycock:
Use PHP to calculate the Path for you:

[php]

$link_url = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/" . "page2.php";


[/php]
that will execute any php code before including it, I believe. Useuld use include( $_SERVER['DOCUMENT_ROOT'] . "/blog/page2.php" )
     
Peter  (op)
Addicted to MacNN
Join Date: Oct 2002
Location: England | San Francisco
Status: Offline
Reply With Quote
Jun 16, 2004, 04:10 AM
 
Originally posted by philzilla:
stone the flamin' crows, ya flamin' galah. provide us with a working URL to check out, Peter, before Mundy turns into Alf Stewart again!
O_O
hejog.net
we don't have time to stop for gas
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Jun 16, 2004, 05:25 AM
 
Originally posted by leperkuhn:
that will execute any php code before including it, I believe. Useuld use include( $_SERVER['DOCUMENT_ROOT'] . "/blog/page2.php" )
Yes - sorry, that was copy / pasted directly out of some code - I assumed that people would pick out the relevant bit
     
Occasionally Useful
Join Date: Jun 2001
Location: Liverpool, UK
Status: Offline
Reply With Quote
Jun 16, 2004, 01:23 PM
 
Originally posted by Diggory Laycock:
Yes - sorry, that was copy / pasted directly out of some code - I assumed that people would pick out the relevant bit
never assume, Diggers. this is MacNN.
"Have sharp knives. Be creative. Cook to music" ~ maxelson
     
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Jun 16, 2004, 01:44 PM
 
Are you sure php can't use relative paths for includes?

Using php5RC3 on a slackware linux box I have lying around at work allows reuired('something.whatever'); to work. I assumed required and include would use the same method of getting the file... or is it because I haven't included a path, just the name of a file in a directory?

I dunno - this euro2004 business is meaning I get drunk far too often (like I am now, and it's only 20 to 8... my body thinks it's still time to do things like posting here, but my brain just won't work. ah well).

Anyhoo - ignore me if I'm being a bit on the idiotic side (or even a lot).
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
Senior User
Join Date: Jan 2000
Location: Burlington, VT, USA
Status: Offline
Reply With Quote
Jun 16, 2004, 02:02 PM
 
Originally posted by Black Book:
Are you sure php can't use relative paths for includes?

Using php5RC3 on a slackware linux box I have lying around at work allows reuired('something.whatever'); to work. I assumed required and include would use the same method of getting the file... or is it because I haven't included a path, just the name of a file in a directory?

I dunno - this euro2004 business is meaning I get drunk far too often (like I am now, and it's only 20 to 8... my body thinks it's still time to do things like posting here, but my brain just won't work. ah well).

Anyhoo - ignore me if I'm being a bit on the idiotic side (or even a lot).
PHP can include relative paths, that's not a problem. The original problem had to do with using a absolute path relative to the root of the web site, which you can't do unless you use $_SERVER['DOCUMENT_ROOT'].

Of course, if you drop in an .htaccess file with a line that has

php_value include_path .:/path/that/you/want/to/use

then you can put your libraries in there, and not bother with relative and absolute paths at all.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:35 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2