How can I call a function to test if a user is in an iframe from within a PHP function? I understand that the only way to test this is in Javascript, and it doesn't seem to work when I try passing it as a JS function in PHP using echo '<script type="text/javascript"> ... </script>';
I want to add this to the function which checks if the user is authorized because I need to direct them to different login pages depending upon whether or not they're in an iframe. This function is in a separate file (because it is called on almost every page on the site) so I don't think that I can do it in straight JS.
JS function I'm trying to 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;
}
}