dongshan0202405 2015-02-28 14:25
浏览 79
已采纳

向XMPP服务器发送消息的php函数没有给出日志而且不起作用

Im working on getting a webpage where users input a text in a form and click submit. From there it validates the input and sends it to a php function that uses JAXL 3.0 library to send the message to my XMPP server.

My problem is that when I call the JAXL function nothing just happens. it's like it can't finish the function as the next function never gets it's call. if I swap the order around the other functions gets called but it still doesn't finish the sendmessage() function.

I'm rusty/new in php and I can't get JAXL to provide a log or anything to debug where my issue is.

If anyone know how to debug this php/JAXL function properly it would be a large help.

I've searched the web around and looked at examples for JAXL but can't find my issue :/

EDIT: Tried some debugging with ECHO. I can't get a ECHO out if it's posted below my Create client. If I ECHO right above it works.

My Sendmessage function:

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

My hole .php page:

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

?>
  • 写回答

1条回答 默认 最新

  • douqian2334 2015-03-01 11:24
    关注

    Apprently the issue was that the PLAIN auth. isn't working for JAXL, so changed it to another AUTH and it worked fine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装