kpetsche20 Posted August 27, 2008 Share Posted August 27, 2008 Is it possible to get a website's source code using PHP or javascript? Link to comment https://forums.phpfreaks.com/topic/121607-is-it-possible-to-get-a-websites-source-code-using-php/ Share on other sites More sharing options...
DarkWater Posted August 27, 2008 Share Posted August 27, 2008 The outputted source code for the HTML page? Sure. Not the PHP source though, as that would be insecure. You can just use file_get_contents() or cURL. Link to comment https://forums.phpfreaks.com/topic/121607-is-it-possible-to-get-a-websites-source-code-using-php/#findComment-627274 Share on other sites More sharing options...
kpetsche20 Posted August 27, 2008 Author Share Posted August 27, 2008 I mean the source you get when you right click on a website and click view source, it doesn't show the php, but the HTML. Link to comment https://forums.phpfreaks.com/topic/121607-is-it-possible-to-get-a-websites-source-code-using-php/#findComment-627278 Share on other sites More sharing options...
DarkWater Posted August 27, 2008 Share Posted August 27, 2008 Then yes. Use file_get_contents('http://www.example.com'); or the cURL library. I'd probably recommend the latter because most web hosts have allow_url_fopen off. Link to comment https://forums.phpfreaks.com/topic/121607-is-it-possible-to-get-a-websites-source-code-using-php/#findComment-627279 Share on other sites More sharing options...
kpetsche20 Posted August 27, 2008 Author Share Posted August 27, 2008 Do you know of any good tutorials? Link to comment https://forums.phpfreaks.com/topic/121607-is-it-possible-to-get-a-websites-source-code-using-php/#findComment-627281 Share on other sites More sharing options...
DarkWater Posted August 27, 2008 Share Posted August 27, 2008 For cURL? It's so ridiculously simple to use for simple web page queries (there's also advanced parts of it, but you don't even need those for this). Just look at the PHP manual page for curl_init() and you'll probably have all that you need. Link to comment https://forums.phpfreaks.com/topic/121607-is-it-possible-to-get-a-websites-source-code-using-php/#findComment-627284 Share on other sites More sharing options...
Guest Xanza Posted August 27, 2008 Share Posted August 27, 2008 US GOOGLE! Jeeze. :/ <?php function file_get_contents_curl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); $data = curl_exec($ch); curl_close($ch); return $data; } ?> Link to comment https://forums.phpfreaks.com/topic/121607-is-it-possible-to-get-a-websites-source-code-using-php/#findComment-627314 Share on other sites More sharing options...
The Little Guy Posted August 27, 2008 Share Posted August 27, 2008 or file wrappers: $url = "http://somesite.com/page.html"; $handle =fopen($url,"r"); $contents = fread($handle, filesize($url)); echo htmlentities($contents); Link to comment https://forums.phpfreaks.com/topic/121607-is-it-possible-to-get-a-websites-source-code-using-php/#findComment-627328 Share on other sites More sharing options...
DarkWater Posted August 27, 2008 Share Posted August 27, 2008 ...most hosts have allow_url_fopen off. [/quote Read please. Link to comment https://forums.phpfreaks.com/topic/121607-is-it-possible-to-get-a-websites-source-code-using-php/#findComment-627331 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.