Hello , I'm new in php and here too. I'm trying to write a code using php and html to load another websites in a frame. I tried using file_get_contents and readfile but it just load the home page of secondary website and after starting to surf its not using get_contents anymore. for example , i tried to get_contents for the website: cmyip[dot]com.it shows my hosting IP located in germany 5.112.xxx.xxx in frame , then I start to surf in this html frame and get back to cmyip again. then i'll see my local computer IP. I want to write a code to make all surfing in the html frame using my hosting IP. its just like a proxy for changing IP. I dont wanna use any written script like glype or PHProxy. I also tried to use: function load(); { $url = file_get_contents($_SERVER['PHP_SELF']); echo $url; } and { $url = file_get_contents($_SERVER['HTML_REFERER']); echo $url; } but i dont know how to use this codes. thanks in advance and sorry for my bad english.
HTML referer doesn't exists, its http_referer but making a proxy with this little knowledge of php would be a very very very hard job!
I also think you're not grasping the values you're pulling from $_SERVER. PHP_SELF -- itself... the file tries to load ITSELF -- that would trigger an endless loop burying the server you run it on. HTTP_REFERRER -- this is basically the URL of the page you clicked on an Anchor to get to the PHP file in the first place. For example if you had a simple index.html that contained: <a href="test.php">Test</a> and your test.php was: <?php echo $_SERVER['HTTP_REFERRER']; ?> clicking on the link would output the URL that index.html is at -- NOT really useful for what you are trying to do. What you need is some way to have a FORM on a page that can submit the URL you want the PHP to load when submit -- a good proxy would also take every single anchor and rewrite their HREF's to point at the proxy so they too can be loaded that way. It's a very complex process -- as Eric said it's a quite monumental undertaking if you're just starting out with PHP.
Eric , I Know but I'm new and I need this code very soon. deathshadow , I tried this before, you know its just showing a webpage loaded by my hosting IP, after trying to reach another websites it gonna surf by My Local IP. Here is my code: I Have 2 Files; first index.php: <html> <head> <title>TEST</title> <style> body { width: 1000px; margin: 0 auto; text-align: center; } #frame { width: 998px; margin: 0 auto; height: 800px; </style> </head> <body> Sallam <p> <iframe src="url.php" id="frame"> </iframe> </body> </html> Code (markup): and Second url.php: <a href="http://cmyip.com">cmyip</a> <?php $link = $_SERVER['HTTP_REFERRER']; $url = readfile($link); echo $url; ?> Code (markup): I have used the code above without HTTP_REFERRER before and it just shows the home page and any click in the Frame will load by my local IP. I'm trying to load the whole website in the frame to open by my Hosting IP, just like a proxy !
You're really just not grasping the scope of what you are trying to do, or the code you are attempting to use... read my post again carefully. Your calling HTTP_REFERRER means when that frame loads, it will load the index.html with it's iframe containing url.php containing the index.html with it's iframe containing url.php containing the index.html with it's iframe containing url.php containing the index.html with it's iframe containing url.php containing the index.html with it's iframe containing url.php containing the index.html with it's iframe containing url.php containing the index.html with it's iframe containing url.php containing the index.html with it's iframe containing url.php containing the index.html with it's iframe containing url.php containing the index.html with it's iframe containing url.php containing the index.html with it's iframe containing url.php containing the index.html with it's iframe containing url.php containing the index.html with it's iframe containing url.php containing the index.html with it's iframe containing url.php containing the index.html with it's iframe containing url.php containing the index.html ... ad nauseum. Get what I'm saying? That code is like pointing a mirror at a mirror. ... and of course clicking on links in the iframe opens them locally, you didn't change the HREF's of any of the links being loaded in that frame to do so! Just displaying contents once from the server (or worse in an infinite loop as you have in the code above) doesn't change what the links are pointing at or tell your browser to load said links from the server. You have to use PHP to actually Oh, and $url = readfile($link); doesn't make any sense -- readfile reads the file and IMMEDIATELY echo's it out to the client... what it returns for a value is how many bytes were read & echo'd, so all that echo $url does is output the number of bytes read, NOT what was fetched. file_get_contents is likely what should be used there, though that's blocked on a number of hosts; I'd probably be using CURL to handle that, or maybe even PHP's DOM processor. Using the DOM processor's DOMDocument:loadHTML would make isolating elements that have URL's like A, IMG, OBJECT, PARAM, etc,etc... far, far simpler. You'd probably also have to isolate and parse all the CSS files to rewrite any instances of URL so they too are passed through the proxy. If you don't change the markup of the pages you are reading in, clicking on links will just behave as normal. LITERALLY a proxy type website has to REWRITE the code of any site it loads to make sure EVERYTHING is routed through it. Simply reading in the file and dumping it back out is NOT going to accomplish any of that.
Thanks for your reply , So.. I have changed my codes to: 1.php: <style> #frame { width: 1000px; height: 900px; margin: 0 auto; } </style> <iframe src="2.php" id="frame"> </iframe> Code (markup): and 2.php: <?php $url= ('http://www.google.com'); print_r(get_data($url)); /* gets the data from a URL */ function get_data($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); $data = curl_exec($ch); curl_close($ch); return $data; } ?> Code (markup): lets try searching for a blocked site like facebook , after displaying result click on Facebook and I got an error displaying"you dont have access to this website". So I Have to change $url Code (markup): to $_SERVER['HTTP_REFERER']; Code (markup): then I got a Mirror at mirror loop like you said. but no problem , it will load 1.php inside the iframe. I Put a link like cmyip.com with HREF so after clicking on cmyip link it will not use my function anymore and display my local IP. the HTTP_REFERER Code (markup): is not working here. I Have to use any clicked links as an array and I Can't find any other codes. just need to know how to get clicked link by user and put it in the curl function right now. I also tried for input field and use $_GET['link'] Code (markup): but it doesnt work. Im newbie in PHP, I live in Iran and my english is not well. We Used PPTP ,L2TP, SSTP, OpenVPN and HTTPS Proxy to access blocked websites. now I'm trying to use this for my customers. because the government has blocked all ports for VPN and Proxies. I tried using PHProxy and Glype before but they had many many problems because of Java Script and Glype Opens Facebook Mobile Version for its plugin. So... the only way right now is using this codes. I need your helps. I have written some codes about login and membership in PHP with reading forums and toturials. but this one is not easy for me. people need to surf youtube, facebook, twitter and many other in this way. but with this codes i can only display the home page of these websites and they can not login to their accounts. Thanks