Xproterg^vi Posted September 28, 2008 Share Posted September 28, 2008 I am wondering how might one save the source of a localhost iframe to a text file? The $source = file_get_contents(view-source:http://mysite.com/); Doesn't work... Any tips? Quote Link to comment https://forums.phpfreaks.com/topic/126193-source-of-a-local-iframe-as-a-php-variable-to-be-saved-to-txt-file/ Share on other sites More sharing options...
Adam Posted September 28, 2008 Share Posted September 28, 2008 $source = file_get_contents("http://mysite.com/"); will return the source... Quote Link to comment https://forums.phpfreaks.com/topic/126193-source-of-a-local-iframe-as-a-php-variable-to-be-saved-to-txt-file/#findComment-652556 Share on other sites More sharing options...
Xproterg^vi Posted September 28, 2008 Author Share Posted September 28, 2008 Yes it does, and I can get that to work. I need to get around the same domain policy to work with local files. I'm writing a whitepaper on this particular security idea. <?php $DEFAULT_FILE = "index.php"; ?> <?php $url=fopen("url.txt","r"); ?> <?php $file = fgets($url); ?> <?php if (isset($file)) { $file2 = $file; echo "<div class=\"source\">\n"; $content=file_get_contents($file2); echo $content; echo "</div>\n"; } else { $file = $DEFAULT_FILE; } ?> <?php $filename = substr($file2,7) . ".html"; if (is_writable($filename)) { if (!$handle = fopen($filename, 'w')) { echo "Cannot open file ($filename)"; exit; } if (fwrite($handle, $content) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($content) to file ($filename)"; fclose($handle); } else { echo "The file $filename is not writable"; } ?> As you can see, the code works. However, if I use this script, it will not keep the session that I have with the external site alive because the IP is from my server and not from myself. So I'm looking to do this through other avenues. The view-source:http://site.com/ is one of those avenues. Quote Link to comment https://forums.phpfreaks.com/topic/126193-source-of-a-local-iframe-as-a-php-variable-to-be-saved-to-txt-file/#findComment-652576 Share on other sites More sharing options...
DarkWater Posted September 28, 2008 Share Posted September 28, 2008 Why are you using all of the PHP blocks when it can all be contained within one block? Quote Link to comment https://forums.phpfreaks.com/topic/126193-source-of-a-local-iframe-as-a-php-variable-to-be-saved-to-txt-file/#findComment-652604 Share on other sites More sharing options...
Xproterg^vi Posted September 28, 2008 Author Share Posted September 28, 2008 Good question... No real answer for it. Quote Link to comment https://forums.phpfreaks.com/topic/126193-source-of-a-local-iframe-as-a-php-variable-to-be-saved-to-txt-file/#findComment-652606 Share on other sites More sharing options...
Adam Posted September 29, 2008 Share Posted September 29, 2008 How would view-source sort the problem? I don't actually think view-source is anything more than a browser command? (Though it's not actually supported in IE) .. I think sending view-source at the start of the file_get_contents function would just cause it to fail? Quote Link to comment https://forums.phpfreaks.com/topic/126193-source-of-a-local-iframe-as-a-php-variable-to-be-saved-to-txt-file/#findComment-652625 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.