html:
<code><div> <div>用户名:</div><div></div> <div>密码:</div><div></div> <div>验证码:</div><div></div>{{login}} <button class="a_button" type="submit">登录</button> </div><script type="text/javascript" src="js/angular.min.js"></script><script> var app = angular.module('login', []); app.controller('login_input', function ($scope,$http) { $scope.check_login=function(){ var aa = { uname : $scope.login.uname, upassword:$scope.login.upassword, chkcode:$scope.login.chkcode } if($scope.login.uname&&$scope.login.upassword&&$scope.login.chkcode){ $http({ method: 'POST', url: 'login.php', data: aa, }) .success(function(response){ console.log(response); }) } } });</script></code>
php:
<code><?phpheader('Content-type: text/html; charset=gb2312');$params = json_decode(file_get_contents('php://input'), true);require("cfg.php");global $dbh;$user_name= $params["uname"];$user_password= $params["upassword"];$user_chkcode= $params["chkcode"];var_dump(is_register());var_dump($user_name);function is_register(){ global $dbh, $user_name, $user_password; $up = sha1($user_password); $sql = "select user from gggg"; $sth = $dbh->prepare($sql); $sth->bindParam(':username', $user_name); // $sth->bindParam(':pwd', $up); $sth->execute(); $rs = $sth->fetchAll(PDO::FETCH_ASSOC); return $rs;}?></code>
接收到的user_name是乱码,这里是需要设置post时的headers吗?应该如何设置。
出于各种原因,需要最大限度地兼容以前的系统,所以要用gb2312.
本文来*源gaodai^.ma#com搞#代!码网
搞gaodaima代码
回复内容:
html:
<code><div> <div>用户名:</div><div></div> <div>密码:</div><div></div> <div>验证码:</div><div></div>{{login}} <button class="a_button" type="submit">登录</button> </div><script type="text/javascript" src="js/angular.min.js"></script><script> var app = angular.module('login', []); app.controller('login_input', function ($scope,$http) { $scope.check_login=function(){ var aa = { uname : $scope.login.uname, upassword:$scope.login.upassword, chkcode:$scope.login.chkcode } if($scope.login.uname&&$scope.login.upassword&&$scope.login.chkcode){ $http({ method: 'POST', url: 'login.php', data: aa, }) .success(function(response){ console.log(response); }) } } });</script></code>
php:
<code><?phpheader('Content-type: text/html; charset=gb2312');$params = json_decode(file_get_contents('php://input'), true);require("cfg.php");global $dbh;$user_name= $params["uname"];$user_password= $params["upassword"];$user_chkcode= $params["chkcode"];var_dump(is_register());var_dump($user_name);function is_register(){ global $dbh, $user_name, $user_password; $up = sha1($user_password); $sql = "select user from gggg"; $sth = $dbh->prepare($sql); $sth->bindParam(':username', $user_name); // $sth->bindParam(':pwd', $up); $sth->execute(); $rs = $sth->fetchAll(PDO::FETCH_ASSOC); return $rs;}?></code>
接收到的user_name是乱码,这里是需要设置post时的headers吗?应该如何设置。
出于各种原因,需要最大限度地兼容以前的系统,所以要用gb2312.
可以贴下post请求的http信息吗,
应该可以接收的时候先用UTF-8接收,然后要存储或者与其他服务交互在服务端转成gb2312,使用iconv()
@黎明星刻 提供的博客文章 http://blog.gaodaima.com/vera_xue…
我在php中使用如下代码解决了问题:
$params = json_decode(file_get_contents(‘php://input’), true);
require(“cfg.php”);
global $dbh;
$user_name = $params[“uname”];//utf-8
$user_name = iconv(“UTF-8”, “GB2312”, $user_name);