Log where a PHP site is iframed from to a file

Viewed 36

I have made a simple iframe widget that people can put on their websites to share a cause that happened in our country:

<div style="width:100%; display:flex; justify-content:center;"><iframe src="//tobia-web.wz.cz/promoravu/embed/" style="border:none; margin-top:25px; border-radius:10px;" height="150" width="300"></iframe></div>

The site in the iframe is in PHP.
I would like to log where the iframe appeared and was loaded in a separate file, so the file would contain all URLs where the site was loaded from in an iframe.
I know you can detect it, is there a way to log it?

1 Answers

It goes like this:

if (iframeDetected) {
  let xhr = new XMLHttpRequest();  // AJAX isn't even a sound acronym
  xhr.open('POST', your_url, true);  // true for asynchronous
  xhr.responseType = 'text';  // sets HTTP headers
  xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');  // let PHP know you're sending from JS
  xhr.formData = new FormData();  // ends up in $_POST
  formData.append('iframeused', true);  // thus $_POST['iframeused']
  req.send(formData);  // fire and forget
}
Related