1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Opening link in iframe not working

Discussion in 'PHP' started by binary777, Jan 20, 2019.

  1. #1
    I have a webpage that loads inside an iframe. I added the base tag to load the images, styling and to make links work, after clicking on a link I'm getting the error "whatsmyip.com refused to connect". Adding target="name-of-iframe" to all links doesn't work.


    <script type="text/javascript" src="jquery-3.2.1.min.js"></script>
    function getURL(url){
    document.getElementById('frame').src = 'proxy.php?url='+encodeURIComponent(url);
    <button onclick="getURL( 'https://whatsmyip.com/')">Google</button>
    <iframe name="frame" id="frame" width="800" height="600" src=""></iframe>

    $page = get_page($_GET['url']);

    $page = str_replace("<head>","<head><base href=\"".$_GET['url']."\">",$page);

    echo str_replace("<a","<a target=\"frame\"",$page);

    function get_page($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);

    $proxy ='';
    curl_setopt($ch, CURLOPT_PROXY, $proxy);

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_HEADER,0);
    $data = curl_exec($ch);
    curl_close($ch);return $data;}
    binary777, Jan 20, 2019 IP
  2. NetStar

    NetStar Notable Member

    Likes Received:
    Best Answers:
    Trophy Points:
    It helps to understand first what your code does. Do you even know?????

    Your html page shows a button named "Google" (makes no sense). Once you click on it a javascript function invokes setting an iFrame to a PHP script with the URL "whatsmyip.com" as a parameter (makes no sense). THEN your PHP script uses cURL to connect to a PROXY in order to connect to "whatsmyip.com" then displays the ENTIRE html contents after a couple meaningless regex replacements.

    I can tell you either did not write the code or you have no idea whats going on. What are you trying to do?
    It *seems* like you are trying to display your visitors IP address. Is this correct? If so, what you are currently doing would display the proxy's IP. If you didn't use the PROXY it would show your servers IP. But it looks like the web site is blocking the proxy.

    If you want to show your visitors IP address just use the following complex code:

    echo $_SERVER["REMOTE_ADDR"];

    Read a PHP tutorial before touching code.
    NetStar, Feb 2, 2019 IP
    JEET likes this.
  3. JEET

    JEET Notable Member

    Likes Received:
    Best Answers:
    Trophy Points:
    It appears as if you are trying to get the URL already loaded in the iframe, using js,
    then you are using ajax to send that URL to a php script,
    which is then using CURL to fetch the webpage content.

    I think this "whatsmyip" site is rejecting your CURL request.
    Try supplying a useragent string along with the CURL request.
    JEET, Mar 29, 2019 IP