include()给出[function.include]:尝试加载另一个页面时无法打开错误

时间:2012-02-25 09:23:42

标签: php include

我在通过include()函数在我的主php文件中加载php文件时遇到了一些麻烦。起初,它工作正常,但之后它只是给[function:include]:无法打开错误。

这就是一切开始的地方。有一个产品页面(“products.php”)当我点击产品链接时,它必须发送要链接的文件的名称(在本例中为“details.php”)和变量(例如1或2)或者一些数字)所以最后整个网址看起来像“details.php?sent = 2”这个网址我的默认php页面必须包括它是否收到变量。

<?php
$received="";
$receivedlink =$_GET["sentlink"]; //this gets the file to link to name
$received =$_GET["sent"]; //this gets the other variable
print $received." ".$receivedlink; //this is for testing purposes. this shows "2 details.php". all ok here.

if ($received == "") {
    include("products.php"); //if no variable received show the first page
} else {
    print ($receivedlink."?sent=".$received); //this too is for testing purposes. this shows "details.php?sent=2". all ok here
    include($receivedlink."?sent=".$received); //this is where the error occurs
} 
?>

其他部分是我遇到麻烦的部分。点击链接后发送和接收所有变量,我的默认php页面必须通过include()函数显示详细信息页面,它给了我该死的错误。所有文件都已到位。没有变量丢失。所有链接都有效。使用此脚本中的“print”进行的测试表明一切正常。

当点击链接时,是否还有其他功能可以调用以加载不同的页面?

1 个答案:

答案 0 :(得分:1)

include(如果您需要阅读手册页)用于将某些 PHP代码从某些文件插入到调用脚本中。不包括任何“页面”。

磁盘上没有名为details.php?sent=2文件。有一个文件details.php,您必须包含此文件。

你的代码也不安全。 至少使用basename()函数清理文件名。