0

サイトのナビゲーションに使用するケース機能を使用しようとしています。

ただし、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 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

新しい PHP ファイルを作成するときはいつでもinclude()/require()、インクルード ステートメントがある場所にコードが挿入されているかのようになります。この新しいファイルには、変数への同じアクセス権があります。

于 2012-11-12T17:33:21.227 に答える
1

include()またはにクエリ文字列を渡すことはできませんrequire()

違う:include("work.php?user=$user");

正しい方法は、include("work.php");

$user引き続きアクセスできますwork.php

于 2012-11-12T17:33:32.240 に答える
1

include() にはphpコードが含まれており、現在のコンテキストで実行されます...そのファイルが含まれているファイルの一部であるかのように、パラメータを渡すことはできません

include('file.php')
于 2012-11-12T17:35:15.050 に答える