phpfile-get-contentsbase-tag

Combined file_get_contents and base tag


Here I have code for showing an external page within my page (similar to iframe but I grab the source):

<?php
$url = 'http://www.kupime.com/';
$data = file_get_contents($url);

$data = '<head><base href='.$url.' target="_blank" /></head>'.$data;    

echo $data;
?>

When I call the script, all is OK - but I can't close javascript window and can't see the content... the close link doesn't work. What is the problem? How to solve this?

UPDATE: or is there any function (JS or jquery) which will hide 'DIV' on right click on him. THANKS


Solution

  • Of course using str_replace() to make them invisible.

    Use this:

    <?php
    $url = 'http://www.kupime.com/';
    
    $data = file_get_contents($url);
    
    $data = '<head><base href='.$url.' target="_blank" /><script type="text/javascript">$(document).ready(function(){parent.close_home_banner()});</script></head>'.$data;
    
    $data = str_replace('<div id="active_banner_wrap">', '<div id="active_banner_wrap" style="display:none;"> ' , $data); 
    $data = str_replace('<div id="home_banner_campaign_wrapper">', '<div id="home_banner_campaign_wrapper" style="display:none;"> ' , $data); 
    
    echo $data;
    
    ?>
    

    To avoid javascripts:

    $data =  str_replace('<script>', '<removed>' , $data);
    $data =   str_replace('</script>', '</removed>' , $data);