View Full Version : Grabbing remote page, links/imgs don't work..

04-02-2003, 03:56 PM
When you include a page from another php page on a different domain all the images and links are relative, so none f them work. Is there any way to fix this aside from writting a script that searches for common references (src=,href=,...). Because If I do that, javascripts urls will be much harder. Is there a way to get the file with absolute paths?

04-02-2003, 05:41 PM
When files are included the source targets are originating from the folder that the script that includes the file is in. Example, say you have the main script in /fun and the include in /fun/includes.

In the included script you have to set all of the non-absolute links to show as if the script was in the /fun folder. so if your images folder is /images the image links in the main script as well as the unclude have to be images/file.ext.

You're probably setting the images like ../images/file.ext in the include file. Or so thats what it seems.

Let me know if that helped.

04-02-2003, 06:35 PM
if you had to add "http://domain.whatever/folder/folder before each image that didn't have that, you'd need some form of clever regex.

a sneaky (and also untested) workaround it to sling a <base href=" at the top of their included output - that should ignore hrefs and srcs that start http and just effect the rest.

echo '<base href="' .substr($file,0,strrpos('/',$file)). '">';

couldn't remember which way the strrpos accepts its parameters either.