2011-03-30 122 views
1

我有这样的PHP代码 -为什么我的PHP包含功能无法正常工作?

<?php include('res/scripts/php/content_type/form_contents/birth_date_form.php?type=register&query=birth_month'); ?> 

正如你可以看到,我包括它?type&query,所以它是错误的或者有别的东西哪去错了。因为它显示了我下面的错误---

Warning: include(res/scripts/php/content_type/form_contents/birth_date_form.php?type=register&query=birth_month) [function.include]: failed to open stream: No error in C:\xampp\htdocs\mysharepoint\1.1\res\scripts\php\content_type\register_form.php on line 82 

Warning: include() [function.include]: Failed opening 'res/scripts/php/content_type/form_contents/birth_date_form.php?type=register&query=birth_month' for inclusion (include_path='.;\xampp\php\PEAR') in C:\xampp\htdocs\mysharepoint\1.1\res\scripts\php\content_type\register_form.php on line 82 

但是,消除?type=register&query=birth_month后,我没有得到任何错误! 所以你有什么建议,请让我知道。

在此先感谢!

+0

您是否试图将文件加载为php - 然后运行脚本,或加载脚本在运行后生成的内容? – 2011-03-30 17:31:04

回答

7

您正在尝试包括,如果它是通过网络提供服务,而且还包括将简单地加载本地文件 - 所以没有查询字符串,因为没有处理发生


而且 - 如果你是试图让外部URL是从您的脚本输出,你可以做这样的事情:

echo implode(file('http://localhost/res/scripts/php/content_type/form_contents/birth_date_form.php?type=register&query=birth_month')) 
+0

那么还有别的办法吗? – 2011-03-30 17:28:03

+0

感谢它的工作! – 2011-03-30 17:31:47

3

你不能在通过相对路径查询字符串的URL。如果你需要指定的查询字符串,做一个完整的绝对网址:

include('http://www.example.com/res/scripts/php/content_type/form_contents/birth_date_form.phptype=register&query=birth_month'); 

这需要allow_url_fopen要上。

+0

以及如何做到这一点?我是PHP新手。请帮助我。 – 2011-03-30 17:29:40

+0

你的意思是'allow_url_fopen'?它是php.ini中的配置指令。 http://php.net/manual/en/filesystem.configuration.php – 2011-03-30 17:32:11

+0

这帮助迈克尔!我会保持这一点,并感谢为我提供一个PHP培训的新网站! – 2011-03-30 17:35:59

1

PHP将查找不存在的文件名'birth_date_form.php?type = register & query = birth_month'。

您可以直接在被调用的url中使用变量传递给脚本,而是调用birth_date_form.php。

这应该工作。

+0

我应该牢记这一点,谢谢昆汀! – 2011-03-30 17:36:23

+0

欢迎您!请享用 ! – Quentin 2011-03-30 18:30:29

相关问题