我正在開發一個小程序Twilio service in PHP。 這裏是我的Twilio端代碼:爲什麼PHP include()不適用於Twilio?
<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<?php
$currrentDate = date('Y-m-d', time());
$current = file_get_contents("1.txt");
$current .= "Caller (".$_REQUEST['From'].")";
file_put_contents("1.txt", $current);
$current .= " at ".date("m/d/y G:i:s", time())."<br/>";
file_put_contents("1.txt", $current);
?>
</Response>
這工作得很好,但是當我使用include函數這是行不通的。我把php代碼放到另一個名爲「test.php」的php文件中。
<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<?php
include("test.php");
?>
</Response>
這裏是我的test.php文件。
<?php
$currrentDate = date('Y-m-d', time());
$current = file_get_contents("1.txt");
$current .= "Caller (".$_REQUEST['From'].")";
file_put_contents("1.txt", $current);
$current .= " at ".date("m/d/y G:i:s", time())."<br/>";
file_put_contents("1.txt", $current);
?>
有人能告訴我爲什麼嗎?謝謝!
你能否解釋一下「不工作「更詳細?你預期會發生什麼,實際發生了什麼?我想知道是否有一些你應該提供的連接到Twilio的代碼 - 你可以編輯它嗎?只是你知道,「不起作用」的問題往往會被低估,因爲這不是一個非常有用的問題描述。 – halfer
嗨,thx您的建議。實際上,當我撥打我的twilio號碼時,來電顯示將保存到一個txt文件中。我已經做到了。但是當我使用include函數來包含完全相同的代碼時,它將不起作用。 – nich
嗯,你的第二項代碼輸出''標籤到標準輸出(Apache輸出到瀏覽器,我猜),但'file_put_contents'將內部內容重定向到一個過時的文件。所以,據我所知,你的迴應永遠是空的。不應該'test.php'將'$ current'的內容直接輸出到標準輸出? –
halfer