![]() |
|
Need help - Get links from a remote site - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: PHP (https://sinister.ly/Forum-PHP) +--- Thread: Need help - Get links from a remote site (/Thread-Need-help-Get-links-from-a-remote-site) |
Need help - Get links from a remote site - hacxx - 05-11-2017 Hi, I'm trying to create a php script based on a example but i'm getting nowhere. The goal is to get all the links from a remote site and print them in the browser page. A query example will be something like this http://www.example.com/index.php?url=http://www.remotesite.com/index.php The code i'm using is below: Code: <?php
$url = $_GET["url"]
$html = file_get_contents('$url');
$pattern = '/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i';
preg_match_all($pattern, $html, $matches);
foreach($matches[0] as $urladdress){
print "Links: " . $urladdress . "<br>";
}
?>Also i would like to include a form in the php page and a way to format the result in html. This way if a request is not made directly it shows the form to the user and if the request is direct show a properly formated text Thanks RE: Need help - Get links from a remote site - zomgwtfbbq - 05-18-2017 It would be easier if you'd explain what didn't work. Anyway, here's a working example. Code: <?php
if(!isset($_GET['url'])){
echo"<form method=\"get\"><input type=\"text\" name=\"url\" /> <input type=\"submit\" name=\"submit\" value=\"Find Links\" /></form>";
}
else{
if($_GET['url']==""){
echo"No url submitted";
}
else{
if(!$sData = @file_get_contents($_GET['url'])){
echo"No data found";
}
else{
preg_match_all('/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i',$sData,$matches);
if(count($matches[0])>0){
echo"Links:<br />\n";
foreach($matches[0] as $urladdress){
echo $urladdress."<br />\n";
}
}
else{
echo"No links found";
}
}
}
}
?>RE: Need help - Get links from a remote site - hacxx - 05-19-2017 "No data found" by form or by direct get. RE: Need help - Get links from a remote site - Darkbyte - 05-19-2017 The code posted works fine , looks like you have a error on your side. Probs connecting to https or file_get_contents turned off or safe mode on.
RE: Need help - Get links from a remote site - hacxx - 05-21-2017 Nah, your kung fu no good. Just kidding... heres a print with another http server and the result is a clean page
|