Allow access to the link only from a specific page?

I'm trying to get a page that can only be accessed from approved websites, but I don’t know exactly how to approach it. Should I just provide a snippet of PHP code that generates a random key and attaches it to the URL, and this key is valid for only one access?

Or is it possible to set a cookie in another domain and then read at the final destination? Maybe it will be a 1px iframe on the start page?

Or am I just trying to do something that never works?

+6
source share
2 answers

In the comments we were able to clarify that ...

I [zen] only need a way to protect the page without having to have credentials for each user or any login. Another option that I thought was to make a POST message every time they click on the link, and my page will only allow them if the POST contains a specific key. [...]

Since the detection of fraudulent access is not a problem, I would suggest that you simply check the http referer for a list of approved sites (and / or pages). It is non-invasive for approved sites and does not provide more reliable protection than the fixed post-token that you are checking.

In PHP, the referrer is in the variable $_SERVER['HTTP_REFERER'] , if any.

+1
source

ok so here is the answer

 <?php $server = $_SERVER['SERVER_NAME']; //Getting Server name $site_name = "http://$server"; //Creating Website URL from SERVER_NAME $url_allowed = array("http://www.allowed1.com", "http://www.allowed2.com"); //Add Allowed Website list Here if(in_array($site_name,$url_allowed)){ echo "<a href='***your link here***'>This is Link</a>"; }else{ echo "This Link is Not Allowed For Your Site"; } ?> 
-2
source

Source: https://habr.com/ru/post/948104/


All Articles