DaGeek247 Posted February 2, 2012 Share Posted February 2, 2012 I have a bit of code (maybe a lot, i dunno) that works pretty well. However, Im having some issues. Im using file_get_contents() to get a remote page from another server, and then displaying it on the current page. The issue? the images/css/urls are relative to the other domain, and so they don't display. I know httrack uses something like this, but it doesn't show the webpage on the server, it downloads the page. my thoughts are that if i could use some php function to change all urls to not be relative, it would work, but i cant do that. anyway, here is my code, you can try it for yourself too, if you want to to see what i mean. tryit: http://dageek247.tk/viewit/ code: <html> <head> <style type="text/css"> .perc {width:93%; height:90%;} .perk {width:6%; height:90%;} </style> </head> <?PHP if ($_GET['url'] == "") { $url = 'http://dageek247.tk/wordpress/'; } else { $url = $_GET['url']; } ?> <body> <div style="height:25px;width:100%;"> <div id="floatbar" style="background:lightblue; width:100%; height:25px; position:fixed; left:0;top:0; z-index:10;"> <center> <form method='get' action='index.php'> <input type='url' name='url' value='<?PHP echo $url; ?>' class='perc'> <input type='submit' value='Go!' class='perk'> </form> </center> </div> </div> <div id='showview' style='width:100%; height:100%;'> <?php //download the webpage $contents = file_get_contents($url); /* //mess around with the webpages code $contints = explode("\n", $contents); //go through each line and cahnge src and href code foreach( $contints as $key => $value){ //images $eqsrc = "src=\""; $src = strpos($original, $eqsrc); $src_end = $src + strlen($eqsrc); $new_src = substr_replace($value, $eqsrc & $url, $src_end, 0); //links $eqhref = "href=\""; $href = strpos($original, $eqhref); $href_end = $href + strlen($eqhref); $new_href = substr_replace($value, $eqhref & $url, $href_end, 0); } $contents = implode("\n", $contints); */ //attempt to be able to download images this way $_SERVER['HTTP_HOST'] = $url; //fails //view the webpage echo $contents; ?> </div> </body> </html> You can also see how i have tried to change relative urls into absolute ones in the commented out area. it doesnt work. Quote Link to comment https://forums.phpfreaks.com/topic/256272-emulating-foreign-host-domain-for-browser/ Share on other sites More sharing options...
kicken Posted February 2, 2012 Share Posted February 2, 2012 If your bit of code on the page does not depend on any relative urls then you can simply output a <base href> tag on the page containing the url you loaded, the browser will resolve all the relative urls based on that url instead. Quote Link to comment https://forums.phpfreaks.com/topic/256272-emulating-foreign-host-domain-for-browser/#findComment-1313750 Share on other sites More sharing options...
DaGeek247 Posted February 2, 2012 Author Share Posted February 2, 2012 It works, sort of. for example, google displays on it now http://dagek247.tk/viewit/index.php?url=http://www.google.com/ But this website is all messed up. http://dageek247.tk/viewit/index.php?url=http://onemorelevel.com/ Is there a way to have a base css and a base img as well? google doesnt think so.... Oh, and here is the new code if you wanna see it: <?PHP if ($_GET['url'] == "") { $url = 'http://dageek247.tk/wordpress/'; } else { $url = $_GET['url']; } ?> <html> <head> <style type="text/css"> .perc {width:93%; height:90%;} .perk {width:6%; height:90%;} </style> <base href="<?PHP echo $url; ?>" /> </head> <body> <div style="height:25px;width:100%;"> <div id="floatbar" style="background:lightblue; width:100%; height:25px; position:fixed; left:0;top:0; z-index:10;"> <center> <form method='get' action='http://dageek247.tk/viewit/index.php'> <input type='url' name='url' value='<?PHP echo $url; ?>' class='perc'> <input type='submit' value='Go!' class='perk'> </form> </center> </div> </div> <div id='showview' style='width:100%; height:100%;'> <?php //download the webpage $contents = file_get_contents($url); //view the webpage echo $contents; ?> </div> </body> </html> Thanks for the help kicken. Quote Link to comment https://forums.phpfreaks.com/topic/256272-emulating-foreign-host-domain-for-browser/#findComment-1313755 Share on other sites More sharing options...
DaGeek247 Posted February 3, 2012 Author Share Posted February 3, 2012 Alright, so i realised that pretending to be the other domain (or using <base href>) is not what i want, and seeing the way to do it wont work the way i wanted it to. However, you did reply with the right answer to the wrong question, so im marking this as solved, because you answered / solved my question. thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/256272-emulating-foreign-host-domain-for-browser/#findComment-1314233 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.