starkiller
starkiller

Reputation: 31

PHP session not working in IE

Heey people, in the following code my session is not working in IE. i dont know why cause to me there is nothing wrong.

browser.php // here php looks for on what browser your opening the page on:

<?php
session_start();


if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') )
{
   if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Netscape') )
   {
     $browser = 'Netscape ';
   }
   else if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') )
   {
     $browser = 'Firefox';
   }
   else if(strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome'))
   {
       $browser = 'Chrome';
   }
   else if (strpos($_SERVER['HTTP_USER_AGENT'], 'Safari'))
   {
     $browser = 'Safari';
   }
}
else if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') )
{
   if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') )
   {
     $browser = 'Opera ';
   }
   else
   {   
     $browser = 'Explorer';
   }

}
else
{
   $browser = 'Others browsers';
}


$_SESSION['Ibrowser'] = $browser;
?>

Print.php // this is a page where i want to print a pdf due to an iFrame

<?php
session_start();
include("Browser.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>wk demo</title>
<link href="css/main.css" rel="stylesheet" type="text/css" />
<script language="javascript">
function printTrigger(elementId) 
{
    var browser = '<?php echo $_SESSION['Ibrowser']; ?>';
    var iFramePdf = elementId;
    /*alert("hello world");*/
    if(browser == "")
    {
        alert("session is leeg");
    }
    else
    {
        if(browser == 'Explorer')
        {
            //alert("IE");
            window.frames[iFramePdf].focus();
            window.frames[iFramePdf].print();           
        }
        else if(browser == 'Safari')
        {
            //alert("Safari");
            window.frames[iFramePdf].focus();
            window.frames[iFramePdf].print();           
        }
        else if(browser == 'Chrome')
        {
            //alert("Chrome");
            var getMyFrame = document.getElementById(elementId); 
            getMyFrame.focus(); 
            getMyFrame.contentWindow.print();
        }
        else if(browser == 'Firefox')
        {
            //alert("Firefox");
            window.open('http://62291.ict-lab.nl/Stage/VDMdm/pdf.php');
        }
        else
        {
            alert("Onbekende Browser");
        }
    }    
}
</script>

Upvotes: 3

Views: 3152

Answers (1)

Jeremy Harris
Jeremy Harris

Reputation: 24549

IE has issues with cookies and handling iFrames due to P3P (Platform for Privacy Preferences). One solution I found is to include this header in every page that uses cookies:

header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');

Give that a try and let me know how it goes.

Upvotes: 4

Related Questions