Hi folks.. new PHP'er here.. I have created a PHP 'shoutbox' and a couple of my friends have linked to it using an iframe. The IFRAME is hosted on my site. I want to be able to capture the URL of the page that initiated the shoutbox post.

I have tried various $SERVER[xxxx] and it just seems to return MY url.

I think I need javascript and I am trying along these lines but majorly failing!

$cur_host = <script language="JavaScript">parent.location.href;
</script>

How can I define the current parent URL of MY iframe and return it to PHP?

As I said.. I am VERY new at this but have a major interest..

http://www.richsterling.com

    You might want to post in a javascript forum, i am not sure how i would do this.

      10 months later

      Hello,

      Just wondering if you managed to do this in PHP please without javascript???

      Im trying to do something similar... I have a PHP script which is loaded into an Iframe on other peoples sites, i want to track who is using the iframe on their site and maybe even use their CSS file so they can make the iframe contents look like a part of their site but I cant figure out how from URL to get the calling URL or Parents URL...

      Any help would be appreciated 🙂

        Thanks, thats really frustrating now because I wanted to make my Nokia unlocker, so other sites could customise the look of it using Css files stored on their own site, then the unlocker loading their css instead of mine, so I just wanted them to have to pass the css file not the full url... Also wanted to track the Unlocker and see who is using it, shame 🙁

          What they can do is having an iframe refering to a script on their site that will communicate with your server, get the file, then echo it in the iframe...

          This way, any browser won't see the "cross siting" 😉

          Try this and you should understand what I'm talking about 😉

          $strMicrosoft = file_get_contents('http://www.microsoft.com/');
          echo $strMicrosoft;
          

            Problem is with that if they dont have PHP on their hosting plan or if they're using some free web service they wouldnt be able to use it???

            I have the calculator here http://www.mobilephonefx.com/free-nokia-unlocking.html but I just wanted people to be able to customise it but only to an extent... also wanted to know who was using it 🙂 Would having the PHP produce some Javascript to get the URL also not work across servers???

              What would be the limitations of HTTP_REFERER please?

              What if I checked HTTP_REFERER if not valid AND if the user hasnt passed their URL to the script then just use the Default CSS???

                The problem with HTTP_REFERER is that browsers allow people to disable it... so it is totally unreliable... we suggest never to use it as a secure feature...

                  I could do it that way, was just holding back on that because without disabling my current one and forcing current webmasters using it I wouldnt be able to find out who currently has it... Also didnt want to add more information to my own database its hard enough with 2000+ mobile phone offers being updated ever 2 hours lol

                    So if it was disabled it wouldnt just provide any information???

                    E.g so if I had
                    <iframe src="http://www.mobilephonefx.com/free-nokia-unlocking.html?css=ourcss.css" ...></iframe>

                    Then in PHP

                    if $css != fullfilepath{
                    strCSS = file_get_contents( $HTTP_REFERER . $css );
                    }else{
                    strCSS = file_get_contents( fullfilepath );
                    }

                    if empty Use Default CSS

                    This is not exact code, just an example... lol

                      Write a Reply...