简体   繁体   English

获取最后可用的URL

[英]Get last available URL

I am using an API to get the users profile picture. 我正在使用API​​来获取用户个人资料图片。 The call looks something like this 通话看起来像这样

https://familysearch.org/platform/tree/persons/{$rid}/portrait?access_token={$_SESSION['fs-session']}&default=https://eternalreminder.com/dev/graphics/{$default_gender}_default.svg

This link only works for about an hour because the user's session token expires then. 该链接只能工作约一个小时,因为用户的会话令牌会在那时失效。 I was wondering if there was any way to retrieve the last returned returned URL, which would be the direct link to the image, so I could store that in a database. 我想知道是否有任何方法可以检索最后返回的返回URL,这将是指向图像的直接链接,因此我可以将其存储在数据库中。

I have tried Google but I don't really know where to start. 我已经尝试过Google,但我真的不知道从哪里开始。

Thanks in advance! 提前致谢!

I was able to solve my own problem. 我能够解决自己的问题。 It was doing a redirect to get the image and I just needed that URL. 它正在进行重定向以获取图像,而我只需要该URL。 Here is my code that helped me get there. 这是帮助我到达那里的代码。

$url="http://libero-news.it.feedsportal.com/c/34068/f/618095/s/2e34796f/l/0L0Sliberoquotidiano0Bit0Cnews0C12735670CI0Esaggi0Eper0Ele0Eriforme0Ecostituzionali0EChiaccherano0Ee0Eascoltano0Bhtml/story01.htm";
$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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM