duan5362 2011-06-13 14:59
浏览 27
已采纳

从我的站点登录到远程站点

I'm building a website and I need to login to another site and take some info from there. the Problem is that the other site requires a user-name and a password (which I have of course) at it's login page. How can I enter my user-name & password and then pass to the second page to get the info ? I'm trying to do it via php but I just read that mayby curl is required..

thanks !

  • 写回答

1条回答 默认 最新

  • dpt62283 2011-06-13 15:16
    关注

    Use cURL!

    Create a page on your remote page that returns the information (i'd recommend using xml as your format) that you want then grab it like this from the site requesting information.

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://www.yourRemoteWebsite.com/mysecretinformation.php");
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'username=Roee84&password=yourPassword');
    
    $myInfo = curl_exec($ch)
    

    At that point, $myInfo will have whatever information you sent from the other side.

    if you end up using xml, check out http://php.net/manual/en/book.simplexml.php for easy parsing.

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

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了