昨天突發奇想的想完成一個遠程端驗證用戶信息的案例, 通過一下午的努力, 代碼終於完成(本人新手菜鳥都不算)mysql
遠程端代碼:web
/**************這裏連接數據庫等信息****************/sql
$uid = $_POST['uid']; $sql = mysql_query("select * from hui_api where uid = '$uid' ",$dsql);//...連接數據庫後的需求 $c = array(); while ($info=mysql_fetch_array($sql,MYSQL_ASSOC)) { $c = $info; } echo json_encode($c);
這裏輸出的$c 在直接訪問遠程端時沒法顯示, 這個數據直接傳遞到了本地端
本地端代碼:數據庫
$url = "/*提交數據地址*/"; $post_data = array ("uid" => "$uid"); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); $output = curl_exec($ch); curl_close($ch); $content = json_decode($output); $_array = is_object($content) ? get_object_vars($content) : $content; $data = file_get_contents($url);//目的頁面內容獲取 $t = json_decode($data,1);//轉換爲PHP數組 if( $upass==$_array['upass'] && $website==$_array['website'] ){ /*這裏自行數據判斷*/ }