PHP POST请求调试
问题描述:
我有以下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请求我用
$url='list/item/new/index.php'
我用整个URL方案:
$url = 'https://example.com/list/item/new/index.php';`
什么是'$ _POST'看起来像在submit.php('的var_dump($ _ POST)'在的开始提交文件)? –
@NMoeini如预期的那样。下面是转储: '阵列(大小= 2) '项目'=> 阵列(大小= 1) '内容'=>字符串 '测试'(长度= 4) '列表'=> 阵列( size = 1) 'hash'=> string'47f563d25d9b5993bbf6b666dc512684f6806c60' (length = 40)' – ebichuhamster