Iframe中session为空的解决办法

单点登录的时候,遇到Iframe中SESSION为空的问题,简单的处理方法如下:



.Net

Response.AddHeader "P3P”,"CP=CAO PSA OUR”


Java

response.setHeader("P3P", "CP=CAO PSA OUR");



加到页面上任意位置即可。






look54.php: <?php session_start(); require "../db54.php"; if(!isset($_SESSION["username"])) { header("Location: ../login54.php"); exit; } $user = $_SESSION["username"]; ?> <!DOCTYPE html> <html> <head> <title>我的购物车</title> <style> table { width: 100%; border-collapse: collapse; } th, td { padding: 8px; text-align: left; border-bottom: 1px solid #ddd; } img { max-width: 100px; } </style> <script> function openme(row) { row.style.backgroundColor = "#FFFFCC"; } function closeme(row) { row.style.backgroundColor = (row.rowIndex % 2 == 1 ? "#F0F0F0" : ""); } function op(button, id) { // Implement quantity increase/decrease logic } function select_all() { // Implement select all checkboxes } function reset_all() { // Implement reset all checkboxes } function delete_all() { // Implement delete selected items } function na() { return confirm("确定要移除该商品吗?"); } function op(t,id) { value=t.value; //按钮上显示的文字 if(value=='+') { //带参数跳转,兼容Google.ie parent.top.window.location="look54.php?op=add&id="+id; } if(value=='-') { parent.top.window.location="look54.php?op=sub&id="+id; } } </script> </head> <body> <h2>我的购物车</h2> <?php // 显示当前用户信息 - 统一使用username if(isset($_SESSION['username'])) { echo "<p>查看购物车 | 当前用户:" . htmlspecialchars($user) . "</p>"; ?> <form name="cartForm" method="post"> <table border=0 align=center width=100% cellspacing=0 bordercolordark=#9CC7EF cellpadding=4 style="line-height:35px"> <tr bgcolor="#FDF5E6"> <th>选择</th> <th>商品名称</th> <th>商品图片</th> <th>订阅数量</th> <th>单价</th> <th>操作</th> </tr> <?php // 处理"拿掉该商品"超链接删除 if(isset($_GET['id']) && $_GET["op"]=="移除") { $id = $_GET['id']; $sql = "DELETE FROM dingdan54 WHERE id = $id"; if($db54->write($sql)) { echo "<script>alert('拿掉商品成功!')</script>"; } else { echo "<script>alert('拿掉商品失败!')</script>"; echo "<script>location.href('look54.php')</script>"; } } // 处理增减按钮+-操作 if(isset($_GET["op"])) { $op = $_GET["op"]; $id = $_GET['id']; // 获取当前数量 $sql = "SELECT * FROM dingdan54 WHERE id = $id"; $result = $db54->read($sql); if(count($result) > 0) { $current_num = $result[0]['num']; if($op == "add") { $new_num = $current_num + 1; } elseif($op == "sub" && $current_num > 1) { $new_num = $current_num - 1; } else { $new_num = $current_num; } // 更新数量 $update_sql = "UPDATE dingdan54 SET num = $new_num WHERE id = $id"; $db54->write($update_sql); } } // 处理"拿掉选中商品"按钮 if(isset($_GET["str"])) { $ids = explode("|", trim($_GET["str"], "|")); foreach($ids as $id) { if(is_numeric($id)) { $sql = "DELETE FROM dingdan54 WHERE id = $id"; $db54->write($sql); } } echo "<script>alert('拿掉商品成功!')</script>"; echo "<script>location.href('look54.php')</script>"; } // 显示购物车 $cart_sql = "SELECT dingdan54.id AS id, sp54.name AS name, sp54.photo AS photo, SUM(dingdan54.num) AS total_num, sp54.money AS money FROM sp54 JOIN dingdan54 ON sp54.id = dingdan54.sp_id WHERE sp54.id = dingdan54.sp_id AND dingdan54.user = '$user' AND dingdan54.flag = 0 GROUP BY sp54.id, sp54.name, sp54.photo, sp54.money"; $cart_result = $db54->read($cart_sql); $n = count($cart_result); if ($n == 0) { echo "<tr><td colspan='6'>购物车是的!</td></tr>"; }else{ for ($i = 0; $i < $n; $i++) { $item = $cart_result[$i]; echo "<tr " . ($i % 2 == 1 ? "bgcolor='#F0F0F0'" : "") . " onmouseover='openme(this)' onmouseout='closeme(this)'>"; echo "<td><input type='checkbox' name='flag' value='{$item['id']}'></td>"; echo "<td>{$item['name']}</td>"; echo "<td><img src='images/{$item['photo']}' width='30' height='30'></td>"; echo "<td><input type='button' name='enter' value='-' onclick='op(this, {$item['id']})'> <input type='text' name='num{$item['id']}' readonly size='3' style='text-align:center' value='{$item['total_num']}'> <input type='button' name='enter' value='+' onclick='op(this, {$item['id']})'></td>"; echo "<td>{$item['money']}元</td>"; echo "<td><a href='look54.php?op=移除&id={$item['id']}' onclick='return na()'> 移除该商品</a></td>"; echo "</tr>"; } } ?> <tr align="center"> <td colspan="5" style="padding-top:8px;"> <input type="button" name="enter" value="全选" onclick="select_all()"> <input type="button" name="enter" value="全部取消" onclick="reset_all()"> <input type="button" name="enter" value="删除选中商品" onclick="delete_all()"> </td> </tr> </table> <?php $total_sql = "SELECT sp54.money AS money, dingdan54.num AS num FROM sp54, dingdan54 WHERE sp54.id = dingdan54.sp_id AND dingdan54.user = '$user' AND dingdan54.flag = 0"; $total_result = $db54->read($total_sql); $sum = 0; foreach ($total_result as $item) { $sum += $item["money"] * $item["num"]; } echo "应付金额:<b><font color=#FF0000>¥"; echo $sum . " 元"; echo " <a href='trolley54.php'>| 去付款</a>"; ?> </form> <a href="index54.php">继续购物</a> <?php } ?> </body> </html> l54.php: <?php include('../db54.php'); session_start(); $user_id=$_SESSION["id"]?? 0; $sql="select * from user54 where id='$user_id'"; $result=$db54->read($sql); $username=$result[0]["username"]; ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>信安28班54何雨霏PHP实训</title> <meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="robots" content="all,follow"> <link rel="stylesheet" href="../css/bootstrap.css"> <!-- Bootstrap CSS--> <link rel="stylesheet" href="https://www.jq22.com/jquery/bootstrap-4.2.1.css"> <!-- Font Awesome CSS--> <link rel="stylesheet" href="https://www.jq22.com/jquery/font-awesome.4.7.0.css"> <!-- Fontastic Custom icon font--> <link rel="stylesheet" href="css/fontastic.css"> <!-- Google fonts - Roboto --> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700"> <!-- jQuery Circle--> <link rel="stylesheet" href="css/grasp_mobile_progress_circle-1.0.0.min.css"> <!-- Custom Scrollbar--> <link rel="stylesheet" href="vendor/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.css"> <!-- theme stylesheet--> <link rel="stylesheet" href="css/style.default.css" id="theme-stylesheet"> <!-- Custom stylesheet - for your changes--> <link rel="stylesheet" href="css/custom.css"> <!-- Favicon--> <link rel="shortcut icon" href="img/favicon.ico"> <!-- Tweaks for older IEs--><!--[if lt IE 9]> <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script><![endif]--> </head> <body> <!-- Side Navbar --> <nav class="side-navbar"> <div class="side-navbar-wrapper"> <!-- Sidebar Header --> <div class="sidenav-header d-flex align-items-center justify-content-center"> <!-- User Info--> <div class="sidenav-header-inner text-center"><img src="img/avatar-7.jpg" alt="person" class="img-fluid rounded-circle"> <h2 class="h5">Nathan Andrews</h2><span>Web Developer</span> </div> <!-- Small Brand information, appears on minimized sidebar--> <div class="sidenav-header-logo"><a href="index.html" class="brand-small text-center"> <strong>B</strong><strong class="text-primary">D</strong></a></div> </div> <!-- Sidebar Navigation Menus--> <div class="main-menu"> <h5 class="sidenav-heading">Main</h5> <ul id="side-main-menu" class="side-menu list-unstyled"> <li><a href="../index.php"> <i class="icon-home"></i>何雨霏的留言板 </a></li> <li><a href="forms.html"> <i class="icon-form"></i>实训页面1 </a></li> <li><a href="charts.html"> <i class="fa fa-bar-chart"></i>实训页面2 </a></li> <li><a href="tables.html"> <i class="icon-grid"></i>实训页面3 </a></li> <li><a href="#exampledropdownDropdown" aria-expanded="false" data-toggle="collapse"> <i class="icon-interface-windows"></i>Example dropdown </a> <ul id="exampledropdownDropdown" class="collapse list-unstyled "> <li><a href="#">admin</a></li> <li><a href="#">查看购物车</a></li> <li><a href="#">后台管理</a></li> </ul> </li> <li><a href="login.html"> <i class="icon-interface-windows"></i>Login page </a></li> <li> <a href="#"> <i class="icon-mail"></i>Demo <div class="badge badge-warning">6 New</div></a></li> </ul> </div> <div class="admin-menu"> <h5 class="sidenav-heading">Second menu</h5> <ul id="side-admin-menu" class="side-menu list-unstyled"> <li> <a href="#"> <i class="icon-screen"> </i>admin</a></li> <li> <a href=""> <i class="icon-screen"> </i>查看购物车</a></li> <li> <a href=""> <i class="icon-screen"> </i>后台管理</a></li> </ul> </div> </div> </nav> <div class="page"> <!-- navbar--> <header class="header"> <nav class="navbar"> <div class="container-fluid"> <div class="navbar-holder d-flex align-items-center justify-content-between"> <div class="navbar-header"><a id="toggle-btn" href="#" class="menu-btn"><i class="icon-bars"> </i></a><a href="index.html" class="navbar-brand"> <div class="brand-text d-none d-md-inline-block"><span> <?php ?> </span><strong class="text-primary">信安28班54何雨霏PHP实训 <?php echo $username; ?></strong></div></a></div> <ul class="nav-menu list-unstyled d-flex flex-md-row align-items-md-center"> <!-- Notifications dropdown--> <li class="nav-item dropdown"> <a id="notifications" rel="nofollow" data-target="#" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="nav-link"><i class="fa fa-bell"></i><span class="badge badge-warning">12</span></a> <ul aria-labelledby="notifications" class="dropdown-menu"> <li><a rel="nofollow" href="#" class="dropdown-item"> <div class="notification d-flex justify-content-between"> <div class="notification-content"><i class="fa fa-envelope"></i>You have 6 new messages </div> <div class="notification-time"><small>4 minutes ago</small></div> </div></a></li> <li><a rel="nofollow" href="#" class="dropdown-item"> <div class="notification d-flex justify-content-between"> <div class="notification-content"><i class="fa fa-twitter"></i>You have 2 followers</div> <div class="notification-time"><small>4 minutes ago</small></div> </div></a></li> <li><a rel="nofollow" href="#" class="dropdown-item"> <div class="notification d-flex justify-content-between"> <div class="notification-content"><i class="fa fa-upload"></i>Server Rebooted</div> <div class="notification-time"><small>4 minutes ago</small></div> </div></a></li> <li><a rel="nofollow" href="#" class="dropdown-item"> <div class="notification d-flex justify-content-between"> <div class="notification-content"><i class="fa fa-twitter"></i>You have 2 followers</div> <div class="notification-time"><small>10 minutes ago</small></div> </div></a></li> <li><a rel="nofollow" href="#" class="dropdown-item all-notifications text-center"> <strong> <i class="fa fa-bell"></i>view all notifications </strong></a></li> </ul> </li> <!-- Messages dropdown--> <li class="nav-item dropdown"> <a id="messages" rel="nofollow" data-target="#" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="nav-link"><i class="fa fa-envelope"></i><span class="badge badge-info">10</span></a> <ul aria-labelledby="notifications" class="dropdown-menu"> <li><a rel="nofollow" href="#" class="dropdown-item d-flex"> <div class="msg-profile"> <img src="img/avatar-1.jpg" alt="..." class="img-fluid rounded-circle"></div> <div class="msg-body"> <h3 class="h5">Jason Doe</h3><span>sent you a direct message</span><small>3 days ago at 7:58 pm - 10.06.2019</small> </div></a></li> <li><a rel="nofollow" href="#" class="dropdown-item d-flex"> <div class="msg-profile"> <img src="img/avatar-2.jpg" alt="..." class="img-fluid rounded-circle"></div> <div class="msg-body"> <h3 class="h5">Frank Williams</h3><span>sent you a direct message</span><small>3 days ago at 7:58 pm - 10.06.2019</small> </div></a></li> <li><a rel="nofollow" href="#" class="dropdown-item d-flex"> <div class="msg-profile"> <img src="img/avatar-3.jpg" alt="..." class="img-fluid rounded-circle"></div> <div class="msg-body"> <h3 class="h5">Ashley Wood</h3><span>sent you a direct message</span><small>3 days ago at 7:58 pm - 10.06.2019</small> </div></a></li> <li><a rel="nofollow" href="#" class="dropdown-item all-notifications text-center"> <strong> <i class="fa fa-envelope"></i>Read all messages </strong></a></li> </ul> </li> <!-- Languages dropdown --> <li class="nav-item dropdown"><a id="languages" rel="nofollow" data-target="#" href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" class="nav-link language dropdown-toggle"><img src="img/flags/16/GB.png" alt="English"><span class="d-none d-sm-inline-block">English</span></a> <ul aria-labelledby="languages" class="dropdown-menu"> <li><a rel="nofollow" href="#" class="dropdown-item"> <img src="img/flags/16/DE.png" alt="English" class="mr-2"><span>German</span></a></li> <li><a rel="nofollow" href="#" class="dropdown-item"> <img src="img/flags/16/FR.png" alt="English" class="mr-2"><span>French </span></a></li> </ul> </li> <!-- Log out--> <li class="nav-item"><a href="login.html" class="nav-link logout"> <span class="d-none d-sm-inline-block">Logout</span><i class="fa fa-sign-out"></i></a></li> </ul> </div> </div> </nav> </header> <section> <?php require "daohang54.php"; ?> <div class="main"> <?php require "look54.php"; ?> </div> </section> <footer class="main-footer"> <div class="container-fluid"> <div class="row"> <div class="col-sm-6"> <p>Copyright © 信安28班54何雨霏《Web应用与安全管理实训》 All rights reserved.</p> </div> <!--<div class="col-sm-6 text-right"></div>--> </div> </div> </div> </footer> </div> <!-- JavaScript files--> <script src="https://www.jq22.com/jquery/jquery-1.10.2.js"></script> <script src="vendor/popper.js/umd/popper.min.js"> </script> <script src="https://www.jq22.com/jquery/bootstrap-4.2.1.js"></script> <script src="js/grasp_mobile_progress_circle-1.0.0.min.js"></script> <script src="vendor/jquery.cookie/jquery.cookie.js"> </script> <script src="vendor/chart.js/Chart.min.js"></script> <script src="vendor/jquery-validation/jquery.validate.min.js"></script> <script src="vendor/malihu-custom-scrollbar-plugin/jquery.mCustomScrollbar.concat.min.js"></script> <script src="js/charts-home.js"></script> <!-- Main File--> <script src="js/front.js"></script> </body> </html> 页面能显示look54的内容,不能显示l54的框架
最新发布
06-27
在Web开发中,框架嵌套或布局问题通常涉及页面结构、路径引用、服务器配置等多个方面。如果 `l54.php` 页面无法正确显示 `look54.php` 的内容,可能的原因和解决方法如下: ### 1. 检查文件路径与包含方式 PHP中使用 `include`、`require` 或其变体(如 `include_once`)来引入其他PHP文件。确保 `l54.php` 中的代码正确引用了 `look54.php` 文件。 ```php <?php include 'look54.php'; ?> ``` - 如果路径不正确,例如 `look54.php` 不在当前目录或相对路径错误,会导致页面内容未被正确加载。 - 建议使用绝对路径或者通过定义常量的方式统一管理路径: ```php define('ROOT_PATH', __DIR__); include ROOT_PATH . '/look54.php'; ``` ### 2. 验证HTML框架结构(如iframe) 如果 `l54.php` 使用 `<iframe>` 来嵌套 `look54.php` 的内容,需确保以下几点: - **URL路径正确**:检查 `<iframe src="look54.php">` 中的路径是否可访问。 - **跨域限制**:若存在跨域情况,浏览器会阻止嵌套加载,应确保主页面和子页面同源。 - **服务器配置**:某些服务器设置可能会阻止 `iframe` 加载,例如 `X-Frame-Options` 头部设置为 `DENY` 或 `SAMEORIGIN`。 ### 3. 查看PHP输出控制 PHP脚本在输出内容时可能受到输出缓冲控制的影响。例如,使用 `ob_start()` 和 `ob_end_flush()` 控制输出流时,需确保没有提前结束缓冲或多次刷新缓冲。 ```php ob_start(); include 'look54.php'; $content = ob_get_clean(); echo $content; ``` ### 4. 检查服务器日志与错误提示 查看 PHP 错误日志或启用调试模式,确认是否存在以下问题: - 文件未找到(File not found)错误。 - 权限问题导致无法读取文件。 - PHP语法错误阻止了脚本执行。 可通过修改 `php.ini` 设置开启错误报告: ```ini display_errors = On error_reporting = E_ALL ``` ### 5. 确保页面结构完整 如果 `l54.php` 是一个布局模板文件,而 `look54.php` 是其子页面,可以采用模板引擎(如 Smarty、Blade)或自定义布局机制实现内容嵌套。例如: ```php <?php // layout.php function render($view, $data = []) { extract($data); include 'layout.php'; // 主模板 } ?> ``` 在 `layout.php` 中定义占位符: ```php <body> <?php include $view; ?> <!-- 动态替换为 look54.php --> </body> ``` ### 6. 检查CSS与JavaScript对布局的影响 有时页面内容实际已加载,但由于 CSS 样式或 JavaScript 脚本的问题导致内容不可见。例如: - 元素被设置为 `display: none;`。 - JavaScript 异步加载失败或报错。 建议使用浏览器开发者工具(F12)检查 DOM 结构和网络请求状态。 ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值