dongyin6576 2015-09-16 14:37
浏览 10

PHP:如何通过curl登录聊天室

i want to play with curl functions for different examples!
for example i want to login to chatrooms by this code:

<?php
$url = 'http://www.lxchat.ir/';
    $postVars = array('username'=>'Alberto','password'=>'','gender'=>'1');
    $tmpfname = dirname(__FILE__).'/cookie.txt';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch,CURLOPT_TIMEOUT, 60);
    curl_setopt($ch,CURLOPT_POST,TRUE);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$postVars);
    curl_setopt($ch, CURLOPT_COOKIEJAR, $tmpfname);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $tmpfname);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    $run = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
    echo $info['redirect_url'];
?>

but this code didn't work!!! how to resolve this problem?
1- Login to chatroom
2- send a message
please help me ...
Thanks

  • 写回答

1条回答 默认 最新

  • dongme8388 2015-09-16 14:46
    关注

    if you want to provide post data you should use http_build_query. I mean use:

    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postVars));
    

    instead of

    curl_setopt($ch,CURLOPT_POSTFIELDS, $postVars);
    

    It may be your problem.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大