[英]PHP Require makes my page blank?
I have a reporting website that I created and I'm slowly adding functionality to it. 我创建了一个报告网站,并正在向其中缓慢添加功能。 I've just added a part where it is supposed to force a user to log in. It's really just to capture the users CorpID, I don't keep or record the password and it's not required.
我刚刚添加了一个强制用户登录的部分。它实际上只是为了捕获用户的CorpID,我不保留或记录密码,并且不是必需的。
Right now I have the login portion working. 现在,我的登录部分正在工作。 Then I'm trying to run a check to make sure that a user is logged in and if not to force them to log in. I am only doing this right now on the Admin page, which only I have access to.
然后,我尝试运行检查以确保用户已登录,如果不想强迫他们登录,则现在仅在“管理”页面上执行此操作,只有我可以访问该页面。 Here is how I've got it right now:
这是我现在的方法:
AdminPage.php: AdminPage.php:
<body>
<?php
require 'CheckLogin.php';
include 'Menu.php';
?>
Other code for the page 页面的其他代码
CheckLogin.php: CheckLogin.php:
<?php
$Expiration = time() - (60*60*24*7);
echo "You made it to here!";
if(!isset($_COOKIE['UserName']))
{
if(isset($_POST['UserName']))
{
setcookie("UserName",$_POST['UserName'],$Expiration);
}
else
{
echo "<script>location.href='LoginForm.php'</script>";
}
}
else
{
if(isset($_POST['UserName']))
{
setcookie("UserName",$_POST['UserName'],$Expiration);
}
else
{
setcookie("UserName",$_COOKIE['UserName'],$Expiration);
}
}
?>
UPDATE 更新
Here's the Menu.php 这是Menu.php
<?php
$AdminUsers = include 'AdminUsernames.php';
if(isset($_COOKIE['UserName']) && in_array($_COOKIE['UserName'],$AdminUsers,TRUE))
{
$user = 'Admin';
}
else
{
$user = 'User';
}
//echo "<BR>"; print_r($_COOKIE['UserName']);
//echo "<BR>"; print_r($AdminUsers);
?>
<div class="menu-wrap">
<nav class="menu">
<ul class="clearfix" id="menu">
<li><a href="index.php">Home</a></li>
<li><a href="AdvancedSearch.php?PageName=AdvancedSearch">Report Builder</a></li>
<li><a href="OPR Reports.php">OPCEN Reports</a>
<ul class="sub-menu">
<li><a href="ReportPage.php?PageName=OPR_COEI">New COEI OPR Report</a></li>
<li><a href="ReportPage.php?PageName=OPR_OSP">New OSP OPR Report</a></li>
<li><a href="ReportPage.php?PageName=EOJ">EOJ Report</a></li>
<li><a href="MaterialTrackingReport.php?PageName=MaterialTracking">Material Tracking</a></li>
<li><a href="ReportPage.php?PageName=VendorMaterial">Vendor Material Tracking</a></li>
<li><a href="http://mafinfwwapv01/Reports_MDAT/Pages/Report.aspx?ItemPath=/PMDB/CAF2 Tracker">CAF2 Tracker</a></li>
<li><a href="JIMReport.php?PageName=JIMReport">JIM Report</a></li>
</ul>
</li>
<li><a href="#">CAFII Reports</a>
<ul class="sub-menu">
<li class="minHeight"><a href="ReportPage.php?PageName=MaterialReceived">Material Received Job Not Started</a></li>
<li class="minHeight"><a href="ReportPage.php?PageName=CAF2Tracker">CAF2 Tracker New Test</a></li>
<?php
include 'DBConn.php';
$data = $conn->prepare('SELECT Id, QName, SSRSName from pmdb.QDefs where QSrc = 2 AND IsActive = 1 order by QName');
$data->execute();
$result = $data->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $q)
{
echo '<li class="minHeight"><a href="http://mafinfwwapv01/Reports_MDAT/Pages/Report.aspx?ItemPath=/PMDB/' . str_replace(' ', '+', $q['SSRSName']) . '" target="_blank">' . $q['QName'] . '</a></li>';
}
?>
</ul>
</li>
<li><a href="#">Invoicing/Closing</a>
<ul class="sub-menu">
<li><a href="ReportPage.php?PageName=NonVarassetInvoices">Non-Varasset Invoices</a></li>
</ul>
</li>
<li><a href="#">ENG Reports</a>
<ul class="sub-menu">
<li><a href="ReportPage.php?PageName=ApprovedProjects">Approved Projects</a></li>
<li><a href="ReportPage.php?PageName=ApprovedProjects_PrevDay">Approved Projects Previous Day</a></li>
<li><a href="ReportPage.php?PageName=M6Action">M6Action</a></li>
</ul>
</li>
<?php
if($user == 'Admin')
{
include 'AdminMenu.php';
}
?>
</ul>
</nav>
</div>
It's really just a standard menu and has been working fine till I added the require
for the CheckLogin.php
page. 它实际上只是一个标准菜单,并且在我为
CheckLogin.php
页面添加require
之前一直工作良好。
All I get is a blank page when I have this require
in the AdminPage.php
. 当我在
AdminPage.php
有此require
时,我得到的只是一个空白页。 I don't get the echo
I don't get the menu or anything. 我
echo
我听不到菜单或其他任何东西。
What am I doing wrong? 我究竟做错了什么? This isn't the first time that I've used the
require
, but it is the first time that it results in a blank page. 这不是我第一次使用
require
,但这是第一次导致空白页面。
I do know that I have the expiration set to last week, I'm trying to force a re-login. 我确实知道我的到期日设置为上周,我正试图强制重新登录。
Using Doug's suggestion from above I found the error. 从上面使用道格的建议,我发现了错误。 In using the
require
I did not use the full path for the file and so it could not be opened. 在使用
require
我没有使用文件的完整路径,因此无法打开它。 What that line should look like is: 该行应如下所示:
require 'Helper/LoginCheck.php';
Put the following in your script before any includes or requires. 将以下内容放入您的脚本中,然后再包含或要求任何内容。
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.