Test if page is in an iframe from within a PHP function -


how can call function test if user in iframe within php function? understand way test in javascript, , doesn't seem work when try passing js function in php using echo '<script type="text/javascript"> ... </script>';

i want add function checks if user authorized because need direct them different login pages depending upon whether or not they're in iframe. function in separate file (because called on every page on site) don't think can in straight js.

js function i'm trying call

 var isiniframe = (window.location != window.parent.location)   function test_iframe() {  if (isiniframe === "true") {  window.location.href = "sign_in_iframe.html";  }  else {       window.location.href = "sign_in.html";  } 

php function

function is_user_logged(){     if ( session_id() == ''){         session_start();     }     if(!isset($_session['sess_user_id']) ) {     $logged = "false";     header("location: sign_in.html");     exit();     } else {     $logged = "true";     return $logged;     }            } 

isiniframe === "true" problem. === strict comparison, true !== "true", 1 boolean while other string.

i'd rid of or use if (isiniframe):

function test_iframe() {     if (window.location != window.parent.location) {        window.location.href = "sign_in_iframe.html";     } else {        window.location.href = "sign_in.html";     } } 

also, take @ question more reliable approach frame detection: how identify if webpage being loaded inside iframe or directly browser window?


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -