Jump to content

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


arbol

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.