I have an iframe on a webpage, and from the iframe i want to get the url of the parent window. Yes, i have been searching the web, but i keep getting solutions with JavaScript.
So do your guys know any solutions that only uses PHP?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A server-side script has no way of knowing anything about the client-side without the client side explicitly sending data, e.g. using AJAX.
If you have control over the iframe itself, you could always pass variables along in the query string and access them using
$_GET:HTML
PHP
UPDATE (this might actually be possible)
There might be a way using
$_SERVER['HTTP_REFERER']. An HTML file containing an iframe sends some headers as it requests the file, and one of them appears to be the HTTP_REFERER. I tested this locally and it seems to work.The only downside is you have no idea of knowing whether the referrer is an iframe or not. Again, if you have control over the iframe, you could pass a variable along using the method above saying it’s an iframe, and use the method below to get the URL dynamically.
Example, let’s say this file’s URL is http://example.com/:
The PHP file, we’ll call it file.php: