如何在代码点火器中集成node.js和socket IO.
<script>
// create a new websocket
var socket = io.connect('http://localhost:8000');
// on message received we print all the data inside the #container div
socket.on('notification', function (data) {
var usersList = "<dl>";
$.each(data.users,function(index,user){
usersList += "<dt>" + user.user_name + "</dt>\n" +
"<dd>" + user.user_description + "\n" +
"<figure> <img class='img-polaroid' width='50px' src='" + user.user_img + "' /></figure>"
"</dd>";
});
usersList += "</dl>";
$('#container').html(usersList);
$('time').html('Last Update:' + data.time);
});
</script>
Run Code Online (Sandbox Code Playgroud)
在本提到的SO问题在这里.我的视图文件与codeigniter在,localhost/myproject但nodejs使用侦听端口localhost:8000.那我怎么连接socket IO.喜欢 …
我希望用户在未设置会话时不访问控制器的某些方法.为此,我可以在所有方法中检查会话,如果设置了会话,那么只需转到其他地方重定向到特定页面.由于我有很多方法,如果没有设置会话,我不希望用户访问.它的批量通过所有方法和检查会话.有没有任何快捷方式来获得此功能.
我试过检查会话是控制器的构造函数方法,但它适用于所有方法.但我只想要特定的方法来阻止会话未设置.怎么做.
例:
class dashboard extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->library('session');
$this->load->model('dbmodel');
$this->load->helper('url','form');
//verified user check
if($this->session->userdata("unverified") != FALSE) {
redirect("verify_user");
}
}
//verified user check
}
Run Code Online (Sandbox Code Playgroud)
上面的代码,当用户转到仪表板控制器时,一旦找到"未验证"会话,就会重定向到verify_user控制器.但是我希望能够访问仪表板控制器的某些方法.不是所有方法.每当发现会话时此代码重定向,并且不允许访问仪表板控制器的任何方法.
参考本教程.使用php跟踪上传进度.我想让它在Codeigniter中运行.我没有意识到开始让它在CI中发挥作用.我想上传文件并跟踪进度.
<?php $arr = array("id"=>"myform");
echo form_open_multipart("welcome/uploads",$arr); ?>
<input type="hidden" value="myForm" name="<?php echo ini_get("session.upload_progress.name"); ?>">
<table>
<tr>
<td>file</td>
<td><input type="file" name="images[]" multiple></td>
</tr>
<tr>
<td>name</td>
<td><input type="text" name="naam"></td>
</tr>
<tr>
<td></td>
<td><input type="submit"></td>
</tr>
</table>
<?php echo form_close(); ?>
<div id="bar_blank">
Run Code Online (Sandbox Code Playgroud)
function toggleBarVisibility() {
var e = document.getElementById("bar_blank");
e.style.display = (e.style.display == "block") ? "none" : "block";
}
function createRequestObject() {
var http;
if (navigator.appName == "Microsoft Internet Explorer") {
http = new ActiveXObject("Microsoft.XMLHTTP");
}
else …Run Code Online (Sandbox Code Playgroud) 我想通过jquery打开bootstrap模式.我知道ajax在成功运行时会发出警报.但无法打开模态.这些是我的代码.
$.ajax({
type: "POST",
url: "<?php echo base_url() . 'index.php/application/requestCode'; ?>",
data: {
'apiName': apiName,
'api': api,
'hotel': hotel,
'payment':payment,
'template': template
},
success: function(msg)
{
$("#getCodeModal").modal("toggle");
$("#getCode").html(msg);
}
});
Run Code Online (Sandbox Code Playgroud)
我的模态HTML是:
<!-- Modal -->
<div class="modal fade" id="getCodeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel"> API CODE </h4>
</div>
<div class="modal-body" id="getCode" style="overflow-x: scroll;">
//ajax success content here.
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
在控制台中出错:模态不是函数.
我正在使用自己的逻辑构建具有身份验证和授权的REST APIJWT.它工作得很好.现在,我想根据角色和权限动态设置路由.假设我有数据库结构,如:
角色:
id | name
1 | school
2 | transport
Run Code Online (Sandbox Code Playgroud)
权限:
id | name | controller | routes
1 | view-class-result | ApiController | getClassResult
2 | view-student-result | ApiController | studentResult
3 | download-student-result | ApiController | donwloadSchoolTemplate
Run Code Online (Sandbox Code Playgroud)
Permission_role
role_id | permission_id
1 1
1 2
1 3
Run Code Online (Sandbox Code Playgroud)
现在,我想根据数据库中的角色和权限创建路由.
目前我的路线似乎是:
//All JWT authentication API goes here
Route::group(['middleware' => 'jwt.auth'], function() {
Route::get('user', 'ApiController@getAuthUser');
Route::get('invalidate', 'ApiController@invalidate');
//All authorized API goes here
Route::group(['middleware' => 'ability:school,view-class-result,true'], function() …Run Code Online (Sandbox Code Playgroud)
我想在用户尝试从现有页面导航时显示自定义警告框而不是浏览器默认警报框.使用此代码:
window.onbeforeunload = function(){
return "are you sure?";
}
Run Code Online (Sandbox Code Playgroud)
我可以使用此代码提醒用户他是否有任何未保存的数据并想要离开页面.但是我想用像facebook这样的自己的设计制作自定义警报框.怎么可能?就像是:
window.onbeforeunload = function(){
myownalertbox.show(); //here I want to bind leave page or stay on page button with my own button.
}
Run Code Online (Sandbox Code Playgroud)
我想绑定停留在此页面上并将此页面按钮保留到我的按钮.
提交表单后,我设置的会话将丢失.
我已经构建了会话类来设置新会话,取消设置等等.在wordpress模板的function.php中.
if (!session_id()) {
session_start();
}
include get_template_directory() . "/custom/session.php";
Run Code Online (Sandbox Code Playgroud)
class session {
function __construct() {
}
function set_flashdata($name, $value) {
$_SESSION[$name] = $value;
}
function flashdata($name) {
if (isset($_SESSION[$name])) {
$str = $_SESSION[$name];
return $str;
} else {
return FALSE;
}
}
function userdata($name) {
if (isset($_SESSION[$name])) {
return $_SESSION[$name];
} else {
return FALSE;
}
}
function set_userdata($name, $value) {
$_SESSION[$name] = $value;
}
function unset_userdata($name) {
if (isset($_SESSION[$name])) {
unset($_SESSION[$name]);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试将会话设置为: …
我目前在PHP中使用CURL来请求XML.当在POSTMAN服务中使用相同的流程时,我可以获得成功结果,但是,当在PHP中使用CURL时,我得到CODE - UC SEG状态不允许 - 0003状态.下面是我的CURL请求标头和代码.CURL请求中的标题选项是否出现问题?
function get_xml_response($xmldata) {
error_reporting(E_ALL);
$wsdl = 'https://sws3-crt.cert.sabre.com';
$header = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"\"",
"Content-length: " . strlen($xmldata),
);
$soap_do = curl_init();
curl_setopt($soap_do, CURLOPT_URL, "$wsdl");
curl_setopt($soap_do, CURLOPT_RETURNTRANSFER, true);
curl_setopt($soap_do, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($soap_do, CURLOPT_TIMEOUT, 60);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($soap_do, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($soap_do, CURLOPT_POST, true);
curl_setopt($soap_do, CURLOPT_POSTFIELDS, $xmldata);
curl_setopt($soap_do, CURLOPT_HTTPHEADER, $header);
if (curl_exec($soap_do) === false) {
$err = 'Curl error: ' . curl_error($soap_do);
curl_close($soap_do);
print $err;
return false;
} else …Run Code Online (Sandbox Code Playgroud) 我试图通过验证其他字段和表而不是用户表的电子邮件和密码来生成令牌.我正在使用tymon jwt图书馆.
我有三个字段需要验证才能验证用户身份
table::where(["id"=>"1","mobile"=>"123","otp"=>"asdf"])->get();
Run Code Online (Sandbox Code Playgroud)
因此,如果我在表中找到符合此条件的行,那么我想验证用户并生成带有所需声明的有效令牌.
到目前为止我尝试过的是:
//after check for three fields in DB. If row matches then, $id and $contact are variable from DB.
$customClaims = ['id' => $id, 'mobile' => $contact];
$payload = JWTFactory::make($customClaims);
Run Code Online (Sandbox Code Playgroud)
在尝试这个时,我得到了JWT payload does not contain the required claims.
那么如何使用三个字段对用户进行身份验证并生成带有所需声明的有效令牌$customClaims.
public function verifyOTP(Request $request) {
$otp = $request->otp;
$schoolid = $request->schoolid;
$parent_contact = $request->contactNum;
$verifyOTP = OTP::where(['schoolid' => $schoolid, 'parent_numb' => $parent_contact, 'otp' => $otp])->get();
if ($verifyOTP) {
$customClaims …Run Code Online (Sandbox Code Playgroud) 我无法了解页面中的脚本是如何加载的.我有依赖于其他脚本的jQuery插件.我正在使用timeago jQuery插件.我按顺序加载了这个脚本:
<script src="<?php echo base_url().'content/scripts/jqueryEngine/jquery.js' ?>" type="text/javascript"></script> //jquery library
<script src="<?php echo base_url().'content/scripts/timeago.js' ?>" type="text/javascript"></script> //timeago
<script src="<?php echo base_url().'content/scripts/myscript.js' ?>" type="text/javascript"></script> // Custom scripts that contains ajax.
Run Code Online (Sandbox Code Playgroud)
在document ready我正在初始化timeago.但这不适合我.在控制台中,浏览器显示timeago无法正常运行.我想要的是确保在任何其他脚本运行之前已经加载了timeago.我的脚本还包含多个依赖于timeago的Ajax调用.