0

我正在尝试使用案例功能在我的网站上进行导航。

但是,当我尝试将它与 php 请求一起使用时,它给了我这个错误:

Warning: include(work.php?user=EEN0422) [function.include]: failed to open stream: Operation not permitted in E:\vhosts\example.com\httpdocs\vtlog\browse.php on line 16

Warning: include(work.php?user=EEN0422) [function.include]: failed to open stream: Operation not permitted in E:\vhosts\example.com\httpdocs\vtlog\browse.php on line 16

Warning: include() [function.include]: Failed opening 'work.php?user=EEN0422' for inclusion (include_path='.;./includes;./pear') in E:\vhosts\example.com\httpdocs\vtlog\browse.php on line 16

browse.php 的脚本是:

<?php
$status = $_GET['status'];
$user = $_GET['user'];

switch ($status) {
    case "working":
        include("index2.php");
        break;
    case "log":
        include("admin.php");
        break;
    case "admin":
        include("settings.php");
        break;  
    case "users":
        include("work.php?user=$user");
        break;
}
?>

对于 work.php,这是这里的问题:

<?php
session_start();

if(!$_SESSION['LoggedIn']) header("location: settingsauth.php");


$host="localhost";
$username="root";
$password="root";
$db_name="db";
$tbl_name="log";

$user=$_GET['user'];


mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT *, (UNIX_TIMESTAMP(end) - UNIX_TIMESTAMP(start)) / 60.0 / 60.0 as hours_difference FROM $tbl_name WHERE user='$user'";
$result=mysql_query($sql);
if ($result === false) { echo "An error occurred."; }

?>
<table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>Start</strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>End</strong></td>
<td width="30%" align="center" bgcolor="#E6E6E6"><strong>Kommentar</strong></td>
<td width="15%" align="center" bgcolor="#E6E6E6"><strong>Tid</strong></td>
<td width="5%" align="center" bgcolor="E6E6E6"></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<title>VTLog - <? echo $rows['user']; ?></title>
<tr>    
<td align="center" bgcolor="#FFFFFF"><? echo $rows['start']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['end']; ?></td>
<td align="center" bgcolor="#FFFFFF"><? echo $rows['comment']; ?></td>
<td align="center" bgcolor="#FFFFFF"><?$var = number_format($rows['hours_difference'],2);
$var = number_format($var,1);
echo $var; ?></td>
<td align="center" bgcolor="#FFFFFF"><a href="editwork.php?editid=<? echo $rows['editid']; ?>"><img src="ret.jpg" alt="Ret"></a><form action="workstatus.php" method="get"><input type="hidden" name="editit" value="<? echo $rows['editid']; ?>" /><input type="submit" value="Slet" /></form></td>
</tr>

<?php
}
mysql_close();
?>
<tr>
<td align="left" bgcolor="#E6E6E6"><a href="settings.php">Tilbage til oversigt</a></td><td colspan="2" align="center" bgcolor="#E6E6E6">Total arbejdstid: <?php $var = number_format($rows['hours_difference'],2);
$var = number_format($var,1);
echo $var;?></td><td bgcolor="#E6E6E6" colspan="2"></td>
</tr>
</table>
4

3 回答 3

2

您不包括 Web URL 路径之类的 PHP 文件。

// Wrong
include("work.php?user=$user");

而是这样做:

include("work.php");
// Which now has access to the current variables including $user

每当您include()/require()创建一个新的 PHP 文件时 - 就好像代码被插入到 include 语句所在的位置一样。这个新文件对变量具有相同的访问权限。

于 2012-11-12T17:33:21.227 回答
1

include() 包含 php 代码,然后在当前上下文中执行...就好像该文件是它所包含的文件的一部分一样,您无法传递参数

include('file.php')
于 2012-11-12T17:35:15.050 回答
1

您不能将查询字符串传入include()require()

错误的:include("work.php?user=$user");

正确的做法是,include("work.php");

并且$user仍然可以访问work.php

于 2012-11-12T17:33:32.240 回答