Jump to content

Archived

This topic is now archived and is closed to further replies.

arbol

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

Recommended Posts

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.

Share this post


Link to post
Share on other sites
[code=php:0]
<?php
  $html = file_get_contents('http://site.com/php?p=1');
?>
[/code]

Share this post


Link to post
Share on other sites
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.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 5

wat can i do to fix this?

thanks alot i appreciate ur help

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites
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??

Share this post


Link to post
Share on other sites
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.awardspace.com/phpBB2/index.php?id=' and check the source to see if there was any mysql errors, hence an sql injection vulnerability...

Share this post


Link to post
Share on other sites
[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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.