Jump to content


Photo

how can i retrieve the html code of a page using php?


  • Please log in to reply
8 replies to this topic

#1 arbol

arbol
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 05 July 2006 - 12:27 AM

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.

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 05 July 2006 - 12:30 AM

<?php
  $html = file_get_contents('http://site.com/php?p=1');
?>


#3 arbol

arbol
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 05 July 2006 - 12:38 AM

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 5

Warning: file_get_contents(http://winsec.awards.../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 5

wat can i do to fix this?

thanks alot i appreciate ur help

#4 mrwhale

mrwhale
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 05 July 2006 - 12:38 AM

<?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.";
}

?>


#5 arbol

arbol
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 05 July 2006 - 12:46 AM

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??

#6 mrwhale

mrwhale
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 05 July 2006 - 12:47 AM

What url are you trying to grab?

The site might not allow it.

#7 arbol

arbol
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 05 July 2006 - 12:49 AM

its my site so it does... im making a script to test web apps for sql injections

so im trying to get the source of

http://winsec.awards...2/index.php?id=' and check the source to see if there was any mysql errors, hence an sql injection vulnerability...

#8 mrwhale

mrwhale
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 05 July 2006 - 12:57 AM

<?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>";
}

?>

This works, i tried it

#9 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 05 July 2006 - 01:12 AM

This works... I just tried it.

<?php

  $html = file_get_contents('http://winsec.awardspace.com/phpBB2/index.php?id=1');
  echo $html;

?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users