Link to home
Start Free TrialLog in
Avatar of willsherwood
willsherwood

asked on

HTML base href PHP- desire to have a local scope for base href for images

HTML/<base href >/PHP question:

Overview:
http://a.com/parent.php   PHP-includes   http://a.com/include.html
http://b.com/parent.php   PHP-includes   http://a.com/include.html 
http://a.com/include.html    contains relative <img> links within a.com
a.com and b.com are separate hosting accounts, separate domain names, but by design have a similar parallel directory structure

Details:
I have two separate web sites of which i'm the designer of each and I have full control.
There is a portion of one page (similar/parallel on each site) that has a PHP include that includes an html file, and the text works fine-- it displays in both contexts.

However, there is an image reference in the  html code that has a *relative* <img> link -  of course, it only displays on the web site URL where the jpeg file resides.  (temporarily  i've duplicated the jpeg files in both hosting accounts just to get the project going)

The included html file (and associated images) changes each week, and the updating/editing of that weekly change is sometimes cut and paste and sometime manually entered in a WYSIWYG script web-based  html editor.   Thus it's not as easy as just making the image reference to be an absolute link.  I do not do this weekly update (my client does this, and is not computer savvy)

I'm looking for a way to accomplish the function of base href for a given scope (i.e., the scope of just the include file)-- i could live with the scope starting at the point of the include and remaining in effect for the rest of the parent file (after the include input stream returns to the parent).
I can only find that base href is allowed in the html header and is effective for the entire page.

i would rather not do frames (since the "parent" web page is complex in itself with masthead and sidebar nav menus, etc)

Another constraint is that PHP is set on our servers to not execute code across URLs.  the  home path needs to be where it's called from.   Thus i chose the include to reference an html file type so PHP would  be able to include across domain names (hosting accounts).
Thus this rules out setting a PHP variable that is then concatenated to provide an absolute directory path. or putting code in to reference environment vars to "repair" the link.
It's not efficient/reliable to hope that however the file is edited each week it will copy the image files to the parallel site's corresponding directory location.

any thoughts on how to accomplish displaying the images within the included html file?

thanks
will
ASKER CERTIFIED SOLUTION
Avatar of FSWZach
FSWZach

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FSWZach
FSWZach

Or - as you said - you have access to both - then just put in something like

{HOSTNAME}

where the hostname goes - then its a simple - no possible problems str_ireplace -

(would do that before I woud do the first - as the first - you got the possibility of it being src="http://image" or src='http://image' or src=http://image
>> Another constraint is that PHP is set on our servers to not execute code across URLs.  the  home path needs to be where it's called from.  

I also would be curious on this .... if you make a file with the extension .txt - so it doesnt parse

put it on one server - and include it on the other server - does it execute?

.... put this in testinclude.txt on one account .............

<?

echo file_get_contents("http://www.google.com");


?>


and then this on the other testinclude.php

<?

include("http://domainname.com/testinclude.txt");

?>
Avatar of willsherwood

ASKER

excellent word-arounds, i'll try these next week when time permits;  so i take it there's no official way to set the scope temporarily or for the rest of the document?

will
I am not going to say it doesnt exist.... because I have come to learn that word "impossible" when dealing with anything with computers only means impossible for the person saying it.

... but that said - it would be rather difficult.  An HTML doc never really has a "rest" of the document.  

As you have noted - you put in a base href - and it effects what is before it - same with anything else.

Think of HTML as a building - there is things going on all around the building - unrelated to each other - and just using the HTML to maintain their position in the building.  Whatever is going on in that building - is all going on at the same time.