ユーザーがフォームにテキストを入力して送信をクリックする Web ページの取得に取り組んでいます。そこから入力を検証し、JAXL 3.0 ライブラリを使用して XMPP サーバーにメッセージを送信する php 関数に送信します。
私の問題は、JAXL 関数を呼び出しても何も起こらないことです。次の関数が呼び出されないため、関数を終了できないようです。他の関数の順序を入れ替えると、呼び出されますが、それでも sendmessage() 関数は終了しません。
私はphpで錆びている/新しいので、JAXLにログを提供させたり、問題のある場所をデバッグすることはできません。
この php/JAXL 関数を適切にデバッグする方法を誰かが知っていれば、大きな助けになるでしょう。
Web を検索して JAXL の例を調べましたが、問題が見つかりません:/
編集: ECHO でいくつかのデバッグを試みました。Create クライアントの下に投稿されている場合、ECHO を取得できません。真上に ECHO すると動作します。
私の Sendmessage 機能:
function sendping()
{
//get the form elements and store them in variables
$ping_text=$_POST["pingtext"];
// Config Details
$host = 'example.com';
$user = 'host';
$pass = 'password';
// Create Client
$client = new JAXL(array(
'log_path' => '/var/log/jaxl.log',
'jid' => $user.'@'.$host,
'pass' => $pass,
'log_level' => JAXL_INFO,
'auth_type' => 'PLAIN'
));
// Add Callbacks
$client->add_cb('on_auth_success', function() use ($host, $client, $ping_text) {
$client->send_chat_msg($host.'/announce/online', $ping_text);
$client->send_end_stream();
});
$client->add_cb('on_auth_failure', function($reason) use ($client)
{
$client->send_end_stream();
_info("got on_auth_failure cb with reason: $reason");
});
$client->add_cb('on_disconnect', function() use ($client)
{
_info("got on_disconnect cb");
});
// Startup Client
$client->start();
私の穴.phpページ:
<?php
/*
Template Name: Stahp Ping
*/
require 'jaxl.php';
get_header(); ?>
<div id="hidden_div" style="display:none; margin-left:auto; margin-right:auto; margin-top:20px;
text-align:center;">
<p>Ping has been sent </p>
</div>
<div style="width:850px !important;
margin-left:auto;
margin-right:auto;
margin-top:20px;
text-align:center;" id="pingform">
<form action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI']);?>" method="post" name="stahpbox">
<textarea name="pingtext" rows="8" cols="60"></textarea>
<input type="submit" value="Send Ping" />
</form>
</div>
<script type="text/javascript">
function showHide() {
var div = document.getElementById("hidden_div");
var pingdiv = document.getElementById("pingform");
if (div.style.display == 'none') {
div.style.display = '';
pingdiv.style.display='none';
}
else {
div.style.display = 'none';
pingdiv.style.display = '';
}
}
</script>
<?php
function sendping()
{
//get the form elements and store them in variables
$ping_text=$_POST["pingtext"];
// Config Details
$host = 'example.com';
$user = 'user';
$pass = 'password';
// Create Client
$client = new JAXL(array(
'log_path' => '/var/log/jaxl.log',
'jid' => $user.'@'.$host,
'pass' => $pass,
'log_level' => JAXL_INFO,
'auth_type' => 'PLAIN'
));
// Add Callbacks
$client->add_cb('on_auth_success', function() use ($host, $client, $ping_text) {
$client->send_chat_msg($host.'/announce/online', $ping_text);
$client->send_end_stream();
});
$client->add_cb('on_auth_failure', function($reason) use ($client)
{
$client->send_end_stream();
_info("got on_auth_failure cb with reason: $reason");
});
$client->add_cb('on_disconnect', function() use ($client)
{
_info("got on_disconnect cb");
});
// Startup Client
$client->start();
}
//Validation and redirection to send to jabber
// Initialize variables and set to empty strings
$pingtextERR="";
// Validate input and sanitize
if ($_SERVER['REQUEST_METHOD']== "POST") {
$valid = true; //Your indicator for your condition, actually it depends on what you need. I am just used to this method.
if (empty($_POST["pingtext"])) {
$pingtextERR = "Text is required";
$valid = false; //false
echo "<script type='text/javascript'>alert('$pingtextERR');</script>";
}
//if valid then redirect
if($valid){
echo "<script> showHide(); </script>";
sendping();
}
}
?>