我在我的Instagram会员网站上使用CodeIgniter。
当我第一次尝试登录我的页面时,它会在数据库中插入 id ,但是当我退出并清除会话并尝试再次登录时,我收到错误:
内部服务器错误
这是我在CodeIgniter中的日志错误:
INFO - 2016-12-21 20:47:00 --> Model Class Initialized
DEBUG - 2016-12-21 20:47:00 --> Curl class already loaded. Second attempt ignored.
ERROR - 2016-12-21 20:47:00 --> Query error: Duplicate entry '1962377392' for key 'PRIMARY' - Invalid query: INSERT INTO `instagram` (`id`, `cookies`, `useragent`, `device_id`, `poin`, `username`, `password`) VALUES (1962377392, 'ds_user_id=1962377392; expires=Tue, 21-Mar-2017 13:47:00 GMT; Max-Age=7776000;csrftoken=F2Fp1QNOuUgHiI5CViajxBIGbsMtQtVe; expires=Wed, 20-Dec-2017 13:47:00 GMT; Max-Age=31449600; Path=/;mid=WFqH1AABAAF38OrHQZq5zamd0q2_; expires=Tue, 16-Dec-2036 13:47:00 GMT; Max-Age=630720000;ds_user=akuuntukkamu; expires=Tue, 21-Mar-2017 13:47:00 GMT; Max-Age=7776000;sessionid=IGSCdf7135cf1f12077c510f35ec09282c3dd788e2f4ff528f853ac568decaac3a8e%3AYyOpVdd67K5vajF2sNgjdfiktjX0M4Lg%3A%7B%22_auth_user_id%22%3A1962377392%2C%22_platform%22%3A1%2C%22_auth_user_hash%22%3A%22%22%2C%22asns%22%3A%7B%22108.168.197.83%22%3A36351%2C%22time%22%3A1482328020%7D%2C%22last_refreshed%22%3A1482328020.533396%2C%22_token_ver%22%3A2%2C%22_token%22%3A%221962377392%3AZWU6rOTIIcRFVtSxnaRcW9veaG9fxO2g%3A22f0a849d9858c559db32062a4b4aa0d59a965213f4c4a182ea63256ef32b2a9%22%2C%22_auth_user_backend%22%3A%22accounts.backends.CaseInsensitiveModelBackend%22%7D; expires=Tue, 21-Mar-2017 13:47:00 GMT; HttpOnly; Max-Age=7776000; Path=/;', 'Instagram 6.22.0 Android (11/1.5.3; 240; 480x800; samsung; SM-N9000; SM-N9000; smdkc210; en_US)', 'android-51b39181ee53eec9', 4, 'myinstagramusername', 'myinstagrampassword')
INFO - 2016-12-21 20:47:00 --> Language file loaded: language/english/db_lang.php
这是我的登录表单和ajax:
<?=form_open('users/login', array('class' => 'form-horizontal','id' => 'loginform'))?>
<div id="salsakp" class="input-group col-sm-12"></div>
<div style="margin-bottom: 20px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<?=form_input(array('id' => 'username', 'name' => 'username', 'type' => 'text', 'class' => 'form-control', 'placeholder' => 'Username Anda', 'required' => 'required'))?>
</div>
<div style="margin-bottom: 20px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<?=form_password(array('id' => 'password', 'name' => 'password', 'class' => 'form-control', 'placeholder' => 'Kata Sandi', 'required' => 'required'))?>
</div>
<div style="margin-top:30px" class="form-group">
<div class="col-sm-12 controls">
<button id="btn-login" type="submit" href="#" class="form-control btn btn-info">Masuk</button>
</div>
</div>
<?=form_close()?>
<script>
$(document).ready(function() {
$('#username').focus();
$("form#loginform").submit(function() {
if ($('#username').val().length > 3 || $('#password').val.length > 3) {
var pdata = $(this).serialize();
var purl = $(this).attr('action');
$.ajax({
url: purl,
data: pdata,
timeout: false,
type: 'POST',
dataType: 'JSON',
success: function(hasil) {
$("input").removeAttr("disabled", "disabled");
$("button").removeAttr("disabled", "disabled");
$("#btn-login").html('Masuk');
if (hasil.result) {
window.location.replace(hasil.redirect);
$("#salsakp").html('<div class="alert alert-success" role="alert">Berhasil Login, Anda akan dialihkan..</div>')
} else $("#salsakp").html('<div class="alert alert-warning" role="alert">' + hasil.content + '</div>')
},
error: function(a, b, c) {
$("input").removeAttr("disabled", "disabled");
$("button").removeAttr("disabled", "disabled");
$("#btn-login").html('Masuk');
$("#salsakp").html('<div class="alert alert-warning" role="alert">' + c + '</div>')
},
beforeSend: function() {
$("input").attr("disabled", "disabled");
$("#btn-login").html('Loading..');
$("#salsakp").html('');
$("button").attr("disabled", "disabled")
}
})
}
return false
})
});
</script>
这是我的登录功能
public function login(){
if(!$this->session->userdata('credentials')):
if(!$this->input->post('username')||!$this->input->post('password')) $ret = json_encode(array('result' => 0, 'content' => 'DSMOS has arrived')); else{
$this->load->library('curl');
$get = $this->curl->simple_get('https://www.instagram.com/'.trim($this->input->post('username')).'/');
if($this->curl->info['http_code']<>200) $ret = json_encode(array('result' => 0, 'content' => 'Username/Password salah..')); else{
preg_match('#, "id": "(.*?)", "biography"#',$get,$id);
$this->load->model('instaloader');
if ($this->db->get_where('instagram', array('id' => $id[1]))->num_rows() > 0):
$rows = $this->db->get_where('instagram', array('id' => $id[1]))->row();
$proccess = $this->instaloader->proccess($rows->useragent, 'accounts/login/', 0, $this->instaloader->hook('{"device_id":"'.$rows->device_id.'","guid":"'.$this->instaloader->guid(1).'","username":"'.trim($this->input->post('username')).'","password":"'.trim($this->input->post('password')).'","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}'));
$procc = json_decode($proccess[1]);
if($procc->status<>ok) $ret = json_encode(array('result' => 0, 'content' => 'Username/Password salah..')); else{
preg_match_all('#Set-Cookie: (.+);#',$proccess[0],$d);$cookie='';
for($o=0;$o<count($d[0]);$o++)$cookie.=$d[1][$o].";";
$this->db->where('id', $procc->logged_in_user->pk)->update('instagram', array('cookies' => $cookie, 'username' => $procc->logged_in_user->username, 'password' => trim($this->input->post('password'))));
$ret = json_encode(array('result' => 1, 'redirect' => base_url()));
$this->session->set_userdata('credentials', array('device_id' => $rows->device_id, 'useragent' => $rows->useragent, 'user_id' => $procc->logged_in_user->pk, 'cookie' => $cookie));
}
else:
$this->load->model('instaloader');
$dev_id = $this->instaloader->device_id();
$user_agent = $this->instaloader->useragent();
$proccess = $this->instaloader->proccess($user_agent, 'accounts/login/', 0, $this->instaloader->hook('{"device_id":"'.$dev_id.'","guid":"'.$this->instaloader->guid(1).'","username":"'.trim($this->input->post('username')).'","password":"'.trim($this->input->post('password')).'","Content-Type":"application/x-www-form-urlencoded; charset=UTF-8"}'));
$procc = json_decode($proccess[1]);
if($procc->status<>ok) $ret = json_encode(array('result' => 0, 'content' => 'Username/Password salah..')); else{
preg_match_all('#Set-Cookie: (.+);#',$proccess[0],$d);$cookie='';
for($o=0;$o<count($d[0]);$o++)$cookie.=$d[1][$o].";";
$this->db->insert('instagram', array('id' => $procc->logged_in_user->pk, 'cookies' => $cookie, 'useragent' => $user_agent, 'device_id' => $dev_id, 'poin' => 4, 'username' => $procc->logged_in_user->username, 'password' => trim($this->input->post('password'))));
$ret = json_encode(array('result' => 1, 'redirect' => base_url(), 'content' => 'Berhasil Login,Anda akan dialihkan..'));
$this->session->set_userdata('credentials', array('device_id' => $dev_id, 'useragent' => $user_agent, 'user_id' => $procc->logged_in_user->pk, 'cookie' => $cookie)); }
endif;
}
}
$this->output
->set_content_type('application/json')
->set_output($ret);
else:
redirect(base_url());
endif;
}
那么,如何使查询不重复?
答案 0 :(得分:1)
错误的整数(1962377392),因为数据库中的结构int()
太小,将int()
更改为VARCHAR(128)
答案 1 :(得分:0)
只有在主键列上未应用自动增量时才会发生这种情况。在这种情况下,您的主键列应自动递增。在数据库表结构中检查一次以克服此问题。