douzhang8033 2017-01-04 17:18
浏览 74

使用php curl函数处理弹出登录窗口(netgear路由器)

I've figured out how to use the php curl functions to automatically log into 2 different radios but am having trouble with netgear routers.

The problem is that its login screen consists of a popup window where you enter user/pass and I can't figure out how to process it with the php curl functions.
I tried adding
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
as suggested in an answer to this question post, but it just returned an "invalid login" screen (before, it would just hang at this point so I suppose it is an improvement).

I also tried adding both
curl_setopt($curl_conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
and
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
before it and turning CURLOPT_FOLLOWLOCATION on and off but same result.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $LoginPage);//IP Address followed by :8080
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($curl_conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, $Username . ":" . $Password);
$data = curl_exec($ch);

Update(2018/2/5):
The following gave me part of the settings page for the router! I'll probably have to mess with the html/javascript to get the rest...

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);//10 seconds
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);//kept trying options till it worked
    curl_setopt($ch, CURLOPT_USERPWD, "$Username:$Password");        
    $result = curl_exec($ch);        
    //$resultStatus = curl_getinfo($ch); 
    //print 'ResultStatus:'.print_r($resultStatus) . "<br>"; 
    curl_close($ch);  
    echo($result);
  • 写回答

2条回答 默认 最新

  • douchen7324 2017-01-04 18:04
    关注

    Borrowing from this answer, a header needs to be set. Instead of:

    curl_setopt($curl_conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
    curl_setopt($ch, CURLOPT_USERPWD, $Username . ":" . $Password);
    

    use these options:

    $headers = array(
        'Content-Type:application/json',
        'Authorization: Basic '. base64_encode("$Username:$Password")
    );
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    

    And the option to verify peer's SSL certificate might also need to be set to false:

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?