How do I figure out in my PHP'开发者_如何转开发s code if I am in an iframe or not? I'd like the page to behave slightly differently. I was going to use HTTP_REFERER but that doesn't seem very reliable.
You can't figure it out in PHP. PHP operates entirely on the server side, and there is no request header specifying whether a request is within an IFRAME or not AFAIK.
You would have to generate some JavaScript that finds out whether it is inside a frame, and sends the information back through AJAX. It's a bit complicated - you would have to generate a unique key for every request, and store that somewhere - but possible.
At that point, it's too late to influence the rendering of the page, of course.
If it's you, who decides (or loads) whether the script is called from IFRAME
or not, you could call it with parameter, i.e. script.php?ff=1
- FromFrame and modify accordingly.
How different are your two cases?
If they're completely different, you could always send both to the client, hiding them with DIV tags until it's finished loading, then checking to see if (window.document == document) and showing the appropriate one.
If they're only slightly different, maybe only the styles being different, you could add some JavaScript to load the appropriate CSS file.
精彩评论