douyi3632 2012-01-20 10:02
浏览 32

PHP会话无法在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>
  • 写回答

1条回答 默认 最新

  • dsj2014 2012-01-20 14:26
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题