Search code examples
javascriptphpurliframeparent

get the parent url of iframe in PHP


I am creating a widget that would load in a IFrame and users will be able to place the widget on their own website. How would I get the URL of the website that is using the IFrame in javascript and/or PHP? The IFrame loads a php file.

I have tried "parent.top.location.href" and "parent.document.referrer" in the IFrame page but that is undefined.

I have also tried to echo "$_Server[referrer]" in the IFrame page and that did return the IFrame parent URL, but how easy is it for someone to manipulate the referrer variable? I dont want to get misleading information. The Goal: I created a widget and want to allow registered users to use that widget on their site. I want to be able to find out who is using the widget and if a un-registered user is using it on their site, then the widget would not display


Solution

  • Try with:

    parent.location.href;
    

    or

    parent.document.URL