0

我正在开发一个网页,用户可以在其中输入表单中的文本并单击提交。从那里它验证输入并将其发送到使用 JAXL 3.0 库的 php 函数将消息发送到我的 XMPP 服务器。

我的问题是,当我调用 JAXL 函数时,什么都没有发生。就像它无法完成函数一样,因为下一个函数永远不会被调用。如果我交换其他函数的顺序,则会调用它,但它仍然没有完成 sendmessage() 函数。

我在 php 中生疏/新手,我无法让 JAXL 提供日志或任何东西来调试我的问题所在。

如果有人知道如何正确调试这个 php/JAXL 函数,那将是一个很大的帮助。

我在网上搜索并查看了 JAXL 的示例,但找不到我的问题:/

编辑:尝试使用 ECHO 进行一些调试。如果 ECHO 发布在我的 Create 客户端下方,我将无法获取它。如果我在上面 ECHO 就可以了。

我的发送消息功能:

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();
  }
}

?>
4

1 回答 1

0

显然问题是 PLAIN auth. 不适用于 JAXL,因此将其更改为另一个 AUTH 并且效果很好。

于 2015-03-01T11:24:57.043 回答