Detect when request is for preview generation

Viewed 818

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?

2 Answers

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:

<?php 
require('path\to\LinkPreviewOrigin.php');

$response = LinkPreviewOrigin::isForLinkPreview();
//true or false

I hope to solve your question!

Related