我正在尝试使用cases功能在我的网站上进行导航。
然而,当我试图通过php请求一个GET来使用它时,它给出了这个错误:
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 16browse.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>发布于 2012-11-13 01:33:21
您不包括PHP文件,如web URL路径。
// Wrong
include("work.php?user=$user");取而代之的是:
include("work.php");
// Which now has access to the current variables including $user每当你包含一个新的PHP文件时,就好像代码被插入到include()/require()语句的正确位置一样。这个新文件对变量具有相同的访问权限。
发布于 2012-11-13 01:33:32
不能在include()或require()中传递查询字符串
错误:include("work.php?user=$user");
正确的方法是,include("work.php");
并且仍然可以在work.php中访问$user
发布于 2012-11-13 01:35:15
include()包含php代码,然后在当前上下文中执行...如果该文件是它所包含文件的一部分,则不能传递参数
include('file.php')https://stackoverflow.com/questions/13348501
复制相似问题