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. HTML <html> <head> <script type="text/javascript" src="jquery-3.2.1.min.js"></script> <script> function getURL(url){ document.getElementById('frame').src = 'proxy.php?url='+encodeURIComponent(url); } </script> </head> <body> <button onclick="getURL( 'https://whatsmyip.com/')">Google</button> <iframe name="frame" id="frame" width="800" height="600" src=""></iframe> </body> </html> PHP $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 ='14.207.72.213:8080'; 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;}
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.
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.