Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get URL of parent window without javascript?

Tags:

php

I have a HTML file http://mydomain.com/page1.html:

<!doctype html>
<html>
  <iframe src="http://mydomain.com/page2.php"></iframe>
</html>

In page2.php, I would like to get the url of the "container page", which in this case is the string page1.html.

Is there anyway to do so without javascript?

like image 690
Pacerier Avatar asked Dec 04 '22 15:12

Pacerier


1 Answers

The browser may send the parent's URL as Referer in the HTTP request, so look at $_SERVER['HTTP_REFERER']. That's not guaranteed though. As such, there's no 100% foolproof way. If the client doesn't supply the information in the request, there's nothing else whatsoever you can do on the server side without explicitly passing the parameter in the URL.

like image 54
deceze Avatar answered Dec 07 '22 03:12

deceze