1
<?php
define('PATH', dirname(dirname(__FILE__)).'/');
require_once (PATH.'./wp-blog-header.php');
global $wpdb;
// if(!isset($_POST['username'])){
// //echo $_POST['submit'];
// exit('非法訪問!');
// }
$username = $_POST["username"];
$password = $_POST["password"];
$email = $_POST["email"];
$checkcode = $_POST["checkcode"];
$query_pwd_str = "SELECT password FROM yjhy_users_custom WHERE username=%s";
if($wpdb == null)
echo "wpdb is null";
$pwd_query_result = $wpdb->get_results($wpdb->prepare($query_pwd_str, $username));
$pwd_query_result_count = count($pwd_query_result);
if($pwd_query_result_count == 1){
//已經存在該用戶名,返回數據
// error here
header('Content-type:text/json');
$json_ouput = '{"status":"success","errormsg":"'.$username.'"}';
echo $json_ouput;
}
?>
通過上面的代碼獲得404錯誤,我用的方法post
指PHP文件,它總是與404錯誤的回覆。爲什麼當PHP回聲位置改變
但是,當我修改如下PHP代碼:
<?php
//****************** move the function header() here
header('Content-type:text/json');
//****************** echo "{" here
echo "{";
?>
<?php
define('PATH', dirname(dirname(__FILE__)).'/');
require_once (PATH.'./wp-blog-header.php');
global $wpdb;
// if(!isset($_POST['username'])){
// //echo $_POST['submit'];
// exit('非法訪問!');
// }
$username = $_POST["username"];
$password = $_POST["password"];
$email = $_POST["email"];
$checkcode = $_POST["checkcode"];
$query_pwd_str = "SELECT password FROM yjhy_users_custom WHERE username=%s";
if($wpdb == null)
echo "wpdb is null";
$pwd_query_result = $wpdb->get_results($wpdb->prepare($query_pwd_str, $username));
$pwd_query_result_count = count($pwd_query_result);
if($pwd_query_result_count == 1){
//已經存在該用戶名,返回數據
// error here
$json_ouput = '"status":"success","errormsg":"'.$username.'"';
echo $json_ouput;
}
?>
<?php
//****************** echo "}" here
echo "}";
?>
,然後它的工作原理,服務器響應狀態是200!
我對這個問題感到困惑,並且一整天都在搜索,找不到答案!
爲什麼代碼是這樣工作的?
什麼是'require_once的內容(PATH。 '/可溼性粉劑博客 - header.php文件');'?它顯示的東西或簡單的PHP代碼沒有輸出? – zeflex
require_once(PATH。'。/ wp-blog-header.php'); 我使用WordPress框架,並使用WP提供的$ wpdb對象,所以需要該行。 @zeflex –
好的,但這個文件的內容是什麼?它是否也顯示HTML代碼? – zeflex