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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

absolute urls in variables

Status
Not open for further replies.

AndyatIES

Technical User
Jul 4, 2002
18
GB
I use a variable to set relative links in include files:
eg:

$var = &quot;../../&quot; sets a required relative prefix for [filename] as in: <img src=&quot;<?= $var ?>image.gif&quot;>

but:

$var = &quot; fails to find the file, presumably because of the // being interpreted as a remark

However, I can't escape these (http:\/\/website.com) because they then all come through as characters.

What should the content of my variable's absolute reference be?
 
$url=' // single quotes for literals ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Nice thought, but no joy. Here's my context:

Apache htaccess refers to a custom error401.php page

This error page picks three include files from another directory. These header/footer/rollover script files are also used by other passworded files at various levels.

Normally the page informs the include files of their relative position by setting the path variable (I actually say $depth = &quot;../../&quot;; for example)

Since the error page is thrown up under the URL of the unaccessed page, it alone needs to call the include files with absolute urls and supply them absolute references for all images they use (using the same $depth variable).

The variable works fine with all relative values (eg &quot;../../&quot;:)

It does not work with: $depth = &quot;
and it isn't the quotes.! I find that I can echo the value of $depth in the same file that can't include using an absolute reference. So what am I wrongly assuming about absolute urls in this context?
 
Just to ask the dumb question....

When you combine the prefix and filename, they do form a valid URL to the data in question, right? ______________________________________________________________________
TANSTAAFL!
 
Bah that was my next question... :) ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
The code outputs a correct URL, but that URL doesn't work?

Then, by definition, the URL your code outputs is not correct. Well-formed, maybe. But not correct. ______________________________________________________________________
TANSTAAFL!
 
Thanks for all the suggestions. Interesting one this. Yes, the code and url are definitely correct. If I echo the same code in a link, as I use in the include statement, the link works. It seems PHP simply doesn't like absolute urls in includes because it always tries to relate them to include_paths (?can you confirm?).

The answer, therefore, seems to be that you have to use a relative link in the include, and instead place the root url you require in php.ini as an additional include_path. I can achieve this locally with a C: reference and will try with my webhost ISP later. Bit of a pain though if you do this much and have to get your ISP to set include paths for you.

Live a little, learn a little every day!
 
I didn't see any use of PHP's include() function in the example code from your original post. Your original question used an example of an IMG tag.

include() operates at the filesystem level. Other than the fact that the script engine is invoked by a web server, include() has nothing whatsoever to do with HTTP and so does not use URLs, but rather filesystem paths. And if you tell PHP include('myfile.php'), for example, PHP assumes that the file can be found either in the directory of the script currently being run or somewhere in include_path.

Your example code was for output of an IMG tag, which is handled through HTTP. So the &quot;src&quot; attribute of an IMG tag is a URL: The way to test this is to type in the URL of the image to your browser and see if it can pull up the image. ______________________________________________________________________
TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top