2018 Jul 22Trainingtechnology
iframe is not widely used browser technology anymore, but in a special project we needed to open page in iframe and base on iframe parent url ,set some variables in PHP.
Question :
How can we detect if page opened in iframe , in php ?
Answer :
We cant directly detect in php, As everybody knows ,php is server side script so CAN NOT get user detailed informations.in the other hand we need client side scripts ,I mean JAVASCRIPT , lovely javascript and jquery.
Solution :
We should run this script to detect if in iframe:
                    if(window.self !== window.top)
                            //Page opened in iframe 
                            //Page opened directly
Note : after detect in jquery , we can run php script via ajax inside jquery



detect page is in iframe

detect page is in iframe jquery

detect page is in iframe php