Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

facebook - Get Third Party Web page URL Using PHP

Hello I have a list of facebook links in xls sheet with facebook id something like this enter image description here

and when i go through these links means if i access facbook with id www.facebook.com/7500

i get urls something like this https://www.facebook.com/davesachs/

so my question is i want to do this with PHP, i have a php page which read data from xls sheet my code here:

require_once 'src/SimpleXLSX.php';
if ( $xlsx = SimpleXLSX::parse('fburl.xlsx') ) {
$rows= $xlsx->rows();

foreach($rows as $data){
echo $data[0].'<br>';
}


} else {
echo SimpleXLSX::parseError();
}

its returning all facebook link with id now i want it send to the facbook with id and get the link as explained above and insert in a separate xls sheet, if it is possible please help me to do that.

question from:https://stackoverflow.com/questions/65932998/get-third-party-web-page-url-using-php

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can do something like that, Taken reference from here

<?php 

require_once 'src/SimpleXLSX.php';
if ( $xlsx = SimpleXLSX::parse('fburl.xlsx') ) {
$rows= $xlsx->rows();

foreach($rows as $data){
  getRedirectedUrl($data[0]);
}


} else {
echo SimpleXLSX::parseError();
}


function getRedirectedUrl($link){
$url=$link;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Must be set to true so that PHP follows any "Location:" header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$a = curl_exec($ch); // $a will contain all headers

$url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); // This is what you need, it will return you the last effective URL

// Uncomment to see all headers
/*
echo "<pre>";
print_r($a);echo"<br>";
echo "</pre>";
*/

echo $url; // Voila
}
?>


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...