我正在使用express.js,app.post路由用于验证用户并使用res.redirect()将有效用户重定向到PHP页面,但它不是重定向而是显示Found。重定向至 http://localhost/home.php
我的server.js代码如下:
app.post('/set_node_session', function(req, res){
sess = req.session;
var usermail = req.body.field1;
var password = req.body.field2;
var sql="SELECT * FROM userInfo WHERE userEmail='"+usermail+"'";
con.query(sql, function (err, result, fields) {
if (err) throw err;
sess.user_id=result[0].userId;
sess.first_name=result[0].userFname;
sess.last_name=result[0].userLname;
if(sess.user_id) {
res.redirect('http://localhost/home.php');
}
else {
res.redirect('http://localhost/login.php');
}
});
});
最佳答案
Node :
var resp = sess.user_id ? '1' : '0';
res.send(resp );
在你的 php 中:
$result = curl_exec($ch);
if(result == 1){
header("Location: http://localhost/home.php");
}
else{
header("Location: http://localhost/login.php");
}
die();
关于php - app.post 路由中的express.js res.redirect 未重定向到给定的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46393583/