public function add(){ $this->lottory_record_db=M('Lottery_record'); $this->lottory_db=M('Lottery'); if($_POST['action'] == 'add' ){ $lid = $this->_post('lid'); $wechaid = $this->_post('wechaid'); //$data['sn'] = $this->_post('sncode'); $data['phone'] = $this->_post('tel'); //$data['prize'] = $this->_post('winprize'); $data['wecha_name'] = $this->_post('wxname'); //$data['time'] = time(); //$data['islottery'] = 1; //$data['usenums'] = 1; $rid=intval($this->_post('rid')); if (!$rid){ $thisRecord=$this->lottory_record_db->where(array('lid'=>$lid,'wecha_id'=>$wechaid,'islottery'=>1))->find(); $rid=$thisRecord['id']; } $rollback = $this->lottory_record_db->where(array('lid'=>$lid,'wecha_id'=>$wechaid,'id'=>$rid))->save($data); $record=$this->lottory_record_db->where(array('id'=>$rid))->find(); echo'{"success":1,"msg":"恭喜!尊敬的<font color=red>'.$data['wecha_name'].'</font>请您保持手机通畅!你的领奖序号:<font color=red>'.$record['sn'].'</font>"}'; exit; } }
回复讨论(解决方案)
if($_POST['action'] == 'add' ){
条件 $_POST['action'] == 'add' 不成立,所以 echo 不执行
var_dump($_POST['action']);//输出看看值是什么?确定条件成立?
var_dump($_POST['action']);
条件是成立的,$rollback = $this->lottory_record_db->where(array('lid'=>$lid,'wecha_id'=>$wechaid,'id'=>$rid))->save($data);这句代码也是执行了的,数据库中有数据
那你输出的只是一个 json 串,需要 js 代码去解析呀
是js代码解晰的问题?
下面这段代码在同一页面,却又能弹出提示
public function exchange(){
$this->lottory_record_db=M('Lottery_record');
$this->lottory_db=M('Lottery');
$this->lottory_pw_db=M('Lottery_pw');
if(IS_POST){
$Lottery_pw = $this->lottory_pw_db->where(array('dpassword'=>trim($_POST['parssword'])))->find();
if ($Lottery_pw['dpassword'] != trim($this->_post('parssword'))){
echo'{"success":0,"msg":"密码不正确"}';exit;
}else {
$data['sendtime'] = time();
$data['sendstutas'] = 1;
$data['dname'] = $Lottery_pw['dname'];
$data['dpassword'] = $Lottery_pw['dpassword'];
$this->lottory_record_db->where(array('id'=> intval($_POST['rid'])))->save($data);
echo'{"success":1,"msg":"领取成功","changed":1}';
}
}
}
是js代码解晰的问题?
下面这段代码在同一页面,却又能弹出提示
public function exchange(){
$this->lottory_record_db=M('Lottery_record');
$this->lottory_db=M('Lottery');
$this->lottory_pw_db=M('Lottery_pw');
if(IS_POST){
$Lottery_pw = $this->lottory_pw_db->where(array('dpassword'=>trim($_POST['parssword'])))->find();
if ($Lottery_pw['dpassword'] != trim($this->_post('parssword'))){
echo'{"success":0,"msg":"密码不正确"}';exit;
}else {
$data['sendtime'] = time();
$data['sendstutas'] = 1;
$data['dname'] = $Lottery_pw['dname'];
$data['dpassword'] = $Lottery_pw['dpassword'];
$this->lottory_record_db->where(array('id'=> intval($_POST['rid'])))->save($data);
echo'{"success":1,"msg":"领取成功","changed":1}';
}
}
}
js代码帖出来吧
document.writeln("
function alert(title)
你在那里调用的?
$("#save-btn").bind("click",
function() {
var btn = $(this);
var tel = $("#tel").val();
var wechaid = $("#wechaid").val();
var winprize = $("#winprize").val();
var sncode = $("#sncode").val();
var lid = $("#lid").val();
//var RegPhone = /^([0-9]{11})?$/;
//var falg;
//falg = tel.value.search(RegPhone);
if (!tel) {
alert("请输入正确{pigcms:$lottery.renametel}");
return
}
var submitData = {
sncode : sncode,
tel : tel,
wechaid : wechaid,
winprize:winprize,
rid: {pigcms:$Coupon.rid},
lid : lid,
action : "add"
};
$.post('index.php?g=Wap&m=Coupon&a=add', submitData,
function(data) {
if (data.success == true) {
alert(data.msg);
window.location.href=location.href;
//$("#zjl").hide("slow");
return
} else {
//alert('失败'+data);
return
}
},"json")
});
$("#save-btnn").bind("click",
function () {
var submitData = {
id: {pigcms:$lottery.id},
rid: {pigcms:$Coupon.rid},
parssword: $("#parssword").val()
};
$.post('index.php?g=Wap&m=Coupon&a=exchange', submitData,
function (data) {
if (data.success == true) {
alert(data.msg);
if (data.changed == true) {
window.location.href = location.href;
}
return
} else {alert(data.msg);}
},
"json")
});
有报错误么。
$record=$this->lottory_record_db->where(array('id'=>$rid))->find(); 看看这条语句有没有出错呢。
没有哦,这条语句支掉,再把下面改成如下,还是弹不出来
echo'{"success":1,"msg":"恭喜"}';
exit;
}
if ($Lottery_pw['dpassword'] != trim($this->_post('parssword'))){
echo'{"success":0,"msg":"密码不正确"}';exit;
}else {
$data['sendtime'] = time();
$data['sendstutas'] = 1;
$data['dname'] = $Lottery_pw['dname'];
$data['dpassword'] = $Lottery_pw['dpassword'];
$this->lottory_record_db->where(array('id'=> intval($_POST['rid'])))->save($data);
echo'{"success":1,"msg":"领取成功","changed":1}';
}
}
}
昨晚又测试,发现密码错误的时候会提示,输入正确的时候不提示
如果你确认有进入,那说明上面有代码发生致命错误,停止了。放出错误信息看看。

In PHP, you can use session_status() or session_id() to check whether the session has started. 1) Use the session_status() function. If PHP_SESSION_ACTIVE is returned, the session has been started. 2) Use the session_id() function, if a non-empty string is returned, the session has been started. Both methods can effectively check the session state, and choosing which method to use depends on the PHP version and personal preferences.

Sessionsarevitalinwebapplications,especiallyfore-commerceplatforms.Theymaintainuserdataacrossrequests,crucialforshoppingcarts,authentication,andpersonalization.InFlask,sessionscanbeimplementedusingsimplecodetomanageuserloginsanddatapersistence.

Managing concurrent session access in PHP can be done by the following methods: 1. Use the database to store session data, 2. Use Redis or Memcached, 3. Implement a session locking strategy. These methods help ensure data consistency and improve concurrency performance.

PHPsessionshaveseverallimitations:1)Storageconstraintscanleadtoperformanceissues;2)Securityvulnerabilitieslikesessionfixationattacksexist;3)Scalabilityischallengingduetoserver-specificstorage;4)Sessionexpirationmanagementcanbeproblematic;5)Datapersis

Load balancing affects session management, but can be resolved with session replication, session stickiness, and centralized session storage. 1. Session Replication Copy session data between servers. 2. Session stickiness directs user requests to the same server. 3. Centralized session storage uses independent servers such as Redis to store session data to ensure data sharing.

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

Notepad++7.3.1
Easy-to-use and free code editor
