Reputation: 4228
We have certain action links which are one time use only. Some of them do not require any action from a user other than viewing it. And here comes the problem, when you share it in say Viber, Slack or anything else that generates a preview of the link (or unfurls the link as Slack calls it) it gets counted as used since it was requested. Is there a reliable way to detect these preview generating requests solely via PHP? And if it's possible, how does one do that?
Upvotes: 7
Views: 1832
Reputation: 185
I've looked on the entire internet to solve this problem. And I've found some workarounds to verify if the request is for link preview generation.
Then, I've created a tool to solve it. It's on GitHub: https://github.com/brunoinds/link-preview-detector
You only need to call a single method from the class:
use Brunoinds\LinkPreviewDetector\LinkPreviewDetector;
$response = LinkPreviewDetector::isForLinkPreview();
//returns a boolean (true/false). If it is true, it means the request is coming from a link preview crawler.
I hope to solve your question!
You can install it from Composer using:
composer require brunoinds/link-preview-detector
Upvotes: 0
Reputation: 37048
Not possible with 100% accuracy in PHP alone, as it deals with HTTP requests, which are quite abstracted from the client. Strictly speaking you cannot even guarantee that user have actually seen the response, even tho it was legitimately requested by the user.
The options you have:
Upvotes: 2