function getHash() {
alert('Debug me gethash');
return localStorage.getItem('hash');
}
function getUser() {
return getHash().split('~')[0];
}
function setHash(data) {
alert('Debug sethash');
localStorage.setItem('hash', data);
}
function doAction(action, params, callback) {
alert('Debug me 3');
$.post('../core.php?action=' + action + '&hash=' + getHash(), params, callback);
}
function register() {
alert('debug1');
doAction('register', {
username: $('#register_user').val(),
ref: fromUrl('ref')
}, function(data) {
alert('Debug me 2');
var json = JSON.parse(data);
if (json.hasOwnProperty('error'))
alert(json.error);
else
ready(json);
});
}

$db=new PDO('mysql:dbname=name;host=localhost',
'',
'',
array(PDO::ATTR_ERRMODE=> PDO::ERRMODE_EXCEPTION));
switch ($_GET['action']) {
case'register': if(isset($_POST['username'], $_POST['ref'])) {
$username=$_POST['username'];
if(strlen($username) < 3) error('Username is too short!');
if(strlen($username) > 10) error('Username is too long!'); //N
if(!preg_match('/^[a-zA-Z0-9_]+$/', $username)) error('Username contains invalid characters!');
$ret=$db->prepare("SELECT * FROM users WHERE username=?");
$ret->execute(array($username));
if($ret->fetch()) error('Username already exists!');
$hash=md5(uniqid("", true));
$db->prepare("INSERT INTO users(username,hash,ontime,referral) VALUES(?,?,?,?)")->execute(array($username, $hash, time(), (int)$_POST['ref']));
die(json_encode(array('hash'=>$username.'~'.$hash)));
}
;
}
&#13;
<h2 class="dialog_text">Register</h2>
<input type="text" class="form-control-modal" placeholder="Username" id="register_user">
<button type="button" class="btn btn-modalbuy" class="close" onclick="register()">Sign Up</button>
<div class='smalltext'>By accessing the site I verify that I am at least 18 years old and have read the Terms & Conditions.</div>
<br>
<hr>//PHPCOde $db = new PDO('mysql:dbname=name;host=localhost', '', '', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); switch ($_GET['action']) { case 'register': if(isset($_POST['username'],$_POST['ref'])) { $username = $_POST['username']; if(strlen($username)
<
3) error( 'Username is too short!'); if(strlen($username)>10) error('Username is too long!'); //N if(!preg_match('/^[a-zA-Z0-9_]+$/',$username)) error('Username contains invalid characters!'); $ret = $db->prepare("SELECT * FROM users WHERE username=?"); $ret->execute(array($username)); if($ret->fetch()) error('Username
already exists!'); $hash = md5(uniqid("",true)); $db->prepare("INSERT INTO users(username,hash,ontime,referral) VALUES(?,?,?,?)")->execute(array($username,$hash,time(),(int)$_POST['ref'])); die(json_encode(array('hash'=>$username.'~'.$hash))); }; }
&#13;
我收到POST http://localhost/core.php?action=register&hash=null 500(内部服务器错误)并且XHR已完成加载:POST&#34; http://localhost/core.php?action=register&hash=null&#34;。
不确定它是我的服务器还是代码。但我似乎无法让它发挥作用。今天花了4个小时尝试。
答案 0 :(得分:1)
如果代码有致命错误但错误报告已关闭,则会显示500 Internal Server Error
。
通过php
文件打开错误报告:
ini_set('display_errors', 1);
通过htacces
文件打开错误报告:
php_flag display_errors 1