2012-11-12 56 views
0

我正在嘗試使用案例功能來在我的網站上進行導航。PHP案例和GET

然而,當我試圖用一個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; 
} 
?> 

而對於工作.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> 
+0

你不能使用'include()'傳遞查詢字符串,所以這個構造的參數需要逐個傳遞文件名,例如, 'work.php?user = EEN0422'作爲文件。 –

回答

2

您不包含PHP文件,如網址路徑。

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

而是做到這一點:

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

每當你include()/require()一個新的PHP文件 - 它只是作爲如果代碼是正確的插入,其中包括語句。這個新文件對變量具有相同的訪問權限。

1

您無法通過查詢字符串include()require()

錯誤:include("work.php?user=$user");

正確的方法是,include("work.php");

$user仍處於work.php

1

包括無障礙()包括php代碼,然後在當前上下文中執行......它就好像該文件是它所包含的文件的一部分,您無法通過pa rameters

include('file.php')