将 PHP 添加到 HTML 框架


adding php to html frame

我在将php添加到包含框架的html中时遇到问题。这是我的代码;

    <?php
    session_start();
if (($_SESSION['accesslevel'] != "normal") ||($_SESSION['accesslevel'] != "admin" )) {
?>
    <meta http-equiv="refresh" content="0; url=./login.html">
    <?php}else {?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>METU 3D Panaromic View</title>
<meta name="description" content="File Upload widget with multiple file selection, drag&amp;drop support, progress bar and preview images for jQuery. Supports cross-domain, chunked and resumable file uploads. Works with any server-side platform (Google App Engine, PHP, Python, Ruby on Rails, Java, etc.) that supports standard HTML form file uploads.">
<meta name="viewport" content="width=device-width">
<!-- Bootstrap CSS Toolkit styles -->
<link rel="stylesheet" href="http://blueimp.github.com/cdn/css/bootstrap.min.css">
<!-- Generic page styles -->
<link rel="stylesheet" href="upload/css/style.css">
<!-- Bootstrap styles for responsive website layout, supporting different screen sizes -->
<link rel="stylesheet" href="http://blueimp.github.com/cdn/css/bootstrap-responsive.min.css">
<!-- Bootstrap CSS fixes for IE6 -->
<!--[if lt IE 7]><link rel="stylesheet" href="http://blueimp.github.com/cdn/css/bootstrap-ie6.min.css"><![endif]-->
<!-- Bootstrap Image Gallery styles -->
<link rel="stylesheet" href="http://blueimp.github.com/Bootstrap-Image-Gallery/css/bootstrap-image-gallery.min.css">
<!-- CSS to style the file input field as button and adjust the Bootstrap progress bars -->
<link rel="stylesheet" href="upload/css/jquery.fileupload-ui.css">
<!-- Shim to make HTML5 elements usable in older Internet Explorer versions -->
<!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
    <frameset rows="40px,94%" BORDER=2 >
        <frame src="./normal_menu.html" noresize="noresize" scrolling="no" name="menu"/>
        <frameset cols="25%,75%" BORDER=2>
           <frame src="./map3.php?type=1" name="MAP" />
           <frame src="./view.html?fileName=findik.den.jpg" name="VIEW"/>
        </frameset>
    </frameset>
</head>
<body>
</body>
</html>
<?php}?>

它看不到是否在 php 中,因此它总是重定向到 login.html。我如何在不放弃框架的情况下处理它。

谢谢。

真的应该使用 PHP header 函数而不是 HTML <meta> 标签:

header('Location:login.html');

目前的做法是,您冒着将他们不应该访问的内容发送到客户端的风险,然后重定向。

除此之外,我认为您的实际问题是布尔逻辑,似乎您应该使用布尔 AND,而不是 OR:

if (($_SESSION['accesslevel'] != "normal") && ($_SESSION['accesslevel'] != "admin" )) {

这里的条件没有意义:

if (($_SESSION['accesslevel'] != "normal") ||($_SESSION['accesslevel'] != "admin" )) {

这两个条件之一将始终为真 - $_SESSION['accesslevel']将始终不等于"正常",或不等于"管理员"。(它不能同时等于两者。

您可能的意思是:

if (!($_SESSION['accesslevel'] == "normal" || $_SESSION['accesslevel'] != "admin")) {

我尝试了你的代码。数组 $_SESSION 是空的!根据 php 手册(session_start 部分),"读回调将检索任何现有的会话数据(以特殊的序列化格式存储),并且将被取消序列化,并在读回调将保存的会话数据返回到PHP会话处理时自动填充$_SESSION超全局。因此,如果您之前没有任何会话正在进行,则似乎永远不会填充数组 $_SESSION,并且您对其进行的任何测试都不会给出任何有用的结果。

<?php
session_start();
if (isset($_SESSION['accesslevel']) && !(($_SESSION['accesslevel'] == "normal") || ($_SESSION['accesslevel'] == "admin" ))) {
?>