Is there a way to determine whether the user is using a web page in side and iframe or is it normal browsing using PHP?
3 Answers
You can add some GET parameters to the request while using IFRAME.
<iframe src="http://www.example.com/iframe?iframe=1">
But while non-iframe request there wouldn't be this GET parameter.
You can check is this GET parameter presents and define it in the session.
So there would be different sessions for iframe and usual window.
The solution is to see if the parent's location and the current window's location is the same. If it is the same, then the page was loaded normally, if it is different then the page was loaded in an iframe.
var isInIFrame = (window.location != window.parent.location) ? true : false;
This came from this website. http://www.24hourapps.com/2009/01/check-if-page-is-loaded-in-iframe-using.html, and it came from the SO question here Check if site is inside iframe.
NOTE: In one test, I got a cross browser origin error but that would also only come if the two locations were different.