我有以下POST管道:
的index.php - > submit.php - >列表/項目/新/ index.php文件
index.php具有動作的正常形式 =「submit.php」屬性。 submit.php根據POST變量的內容決定通過某種邏輯發送以下發布請求的位置。
問題是我沒有找到一個成功的方法來調試這個管道。在某個地方,有些東西是失敗的,我會欣賞一雙新鮮的眼睛。
我已經試過
- 我試圖運行列表/項目/新/ index.php文件通過常規GET請求啞參數。數據庫成功更新。
我已經嘗試通過常規GET請求運行submit.php(下面)與虛擬參數。 $結果的價值是不假,指示的file_get_contents請求成功,但它的價值爲列表/新的文字內容/index.php文件,而不是生成的內容,這是我期待向是結果
echo $ db-> new($ hash,$ content)& & $ db-> update_content_key($ hash);
這裏是submit.php
$url = 'list/new/index.php';
if($test){
$content = $_GET["i"];
$hash = $_GET["h"];
}else{
$content = $_POST["item"]["content"];
$hash = $_POST["list"]["hash"];
}
$data = array(
'item'=>array('content' => $content),
'list'=>array('hash' => $hash)
);
$post_content = http_build_query($data);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n".
"Content-Length: " . strlen($post_content) . "\r\n",
'method' => 'POST',
'content' => $post_content
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {
echo "error";
//commenting out for testing. should go back to index.php when it's done
//header('Location: '.$root_folder_path.'list/?h='.$hash.'&f='.$result);
}
else{
var_dump($result);
//commenting out for testing. should go back to index.php when it's done
//header('Location: '.$root_folder_path.'list/?h='.$hash.'&f='.str_replace($root_folder_path,"\n",""));
}
這裏是列表/項目/新/ index.php文件
$db = new sql($root_folder_path."connection_details.php");
if($test){
$content = $_GET["i"];
$hash = $_GET["h"];
}else{
$content = $_POST["item"]["content"];
$hash = $_POST["list"]["hash"];
}
// insert into DB, use preformatted queries to prevent sqlinjection
echo $db->new($hash,$content) && $db->update_content_key($hash);
關於這個最糟糕的事情是,我不知道足夠的PHP來有效地調試這個(我確實在今天的某個時間點工作,但我沒有承諾那麼......)。
歡迎您提出任何意見和建議。我感謝你的時間。
什麼是'$ _POST'看起來像在submit.php('的var_dump($ _ POST)'在的開始提交文件)? –
@NMoeini如預期的那樣。下面是轉儲: '陣列(大小= 2) '項目'=> 陣列(大小= 1) '內容'=>字符串 '測試'(長度= 4) '列表'=> 陣列( size = 1) 'hash'=> string'47f563d25d9b5993bbf6b666dc512684f6806c60' (length = 40)' – ebichuhamster