arbol Posted July 5, 2006 Share Posted July 5, 2006 hey. I am making a web application testing script, and need some help. I want to make it so that I tell the script to go to http://site.com/php?p=1, and then retrieve the source code of the result page and store it in a PHP variable. Is this possible? I would appreciate any help greatly, since I am supposed to have this done by tommorow. Quote Link to comment https://forums.phpfreaks.com/topic/13689-how-can-i-retrieve-the-html-code-of-a-page-using-php/ Share on other sites More sharing options...
trq Posted July 5, 2006 Share Posted July 5, 2006 [code=php:0]<?php $html = file_get_contents('http://site.com/php?p=1');?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13689-how-can-i-retrieve-the-html-code-of-a-page-using-php/#findComment-53108 Share on other sites More sharing options...
arbol Posted July 5, 2006 Author Share Posted July 5, 2006 i get an error when i do that:Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: No address associated with hostname in /home/www/winsec.awardspace.com/arbolsphpfiles/testest.php on line 5Warning: file_get_contents(http://winsec.awardspace.com/phpBB2/index.php?id=1): failed to open stream: Address family not supported by protocol in /home/www/winsec.awardspace.com/arbolsphpfiles/testest.php on line 5wat can i do to fix this?thanks alot i appreciate ur help Quote Link to comment https://forums.phpfreaks.com/topic/13689-how-can-i-retrieve-the-html-code-of-a-page-using-php/#findComment-53110 Share on other sites More sharing options...
mrwhale Posted July 5, 2006 Share Posted July 5, 2006 [code]<?php$url = "http://www.google.com";$file = file( $url );if( $file ){ foreach( $file as $line ) { $x++; echo "line " . $x . ": " . htmlspecialchars( $line ) . "<br>"; }}else{ echo "Page could not be found.";}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13689-how-can-i-retrieve-the-html-code-of-a-page-using-php/#findComment-53111 Share on other sites More sharing options...
arbol Posted July 5, 2006 Author Share Posted July 5, 2006 still get the same error!!it worked for google, but when I tried my php page it didnt work!! is there a way to retrieve a php page at all?? Quote Link to comment https://forums.phpfreaks.com/topic/13689-how-can-i-retrieve-the-html-code-of-a-page-using-php/#findComment-53112 Share on other sites More sharing options...
mrwhale Posted July 5, 2006 Share Posted July 5, 2006 What url are you trying to grab?The site might not allow it. Quote Link to comment https://forums.phpfreaks.com/topic/13689-how-can-i-retrieve-the-html-code-of-a-page-using-php/#findComment-53113 Share on other sites More sharing options...
arbol Posted July 5, 2006 Author Share Posted July 5, 2006 its my site so it does... im making a script to test web apps for sql injectionsso im trying to get the source ofhttp://winsec.awardspace.com/phpBB2/index.php?id=' and check the source to see if there was any mysql errors, hence an sql injection vulnerability... Quote Link to comment https://forums.phpfreaks.com/topic/13689-how-can-i-retrieve-the-html-code-of-a-page-using-php/#findComment-53114 Share on other sites More sharing options...
mrwhale Posted July 5, 2006 Share Posted July 5, 2006 [code]<?php$config[start_url] = "http://winsec.awardspace.com/phpBB2/index.php?id=1";class spider{ var $error = ''; var $links = array(); function graburl( $url ) { $file = file( $url ); if( $file ) { foreach( $file as $line ) { $x++; $this->links[$x] = $line; } } else { $this->error = "Website not found."; exit; } } function get_url( $url ) { $this->graburl( $url ); }}$spider = new spider;$spider->get_url( $config[start_url] );echo $spider->error;foreach( $spider->links as $links ){ echo htmlspecialchars( $links ) . "<br>";}?>[/code]This works, i tried it Quote Link to comment https://forums.phpfreaks.com/topic/13689-how-can-i-retrieve-the-html-code-of-a-page-using-php/#findComment-53118 Share on other sites More sharing options...
trq Posted July 5, 2006 Share Posted July 5, 2006 This works... I just tried it.[code=php:0]<?php $html = file_get_contents('http://winsec.awardspace.com/phpBB2/index.php?id=1'); echo $html;?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13689-how-can-i-retrieve-the-html-code-of-a-page-using-php/#findComment-53121 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.