2011-03-30 106 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

相關問題