duanpang5583 2015-02-04 17:05
浏览 59
已采纳

自动填写表单登录凭据

What I'd like is to hit my link with the result of an auto login to a 3rd party site. Because we don't have direct control of the login site's code, it makes it more challenging. I'm thinking we may just have to give up for now until we can get our clients' programmers to add javascript to parse URLs. Then we can just do a parsed URL link with the username and password. I've looked through tons of solutions already, but every single one of them requires code on the page holding the form (which we don't have access to) for it to work.

Eventually I plan to create a self contained program for us to use, but for now all I know is HTML, a good amount of javascript and just starting on PHP. Currently we're just using the saved login creds stored by cookies in the browsers. This is fine, but I want to stream line the process since we have way too many client logins. It would be so nice to have auto-login.

I had seen something using curl to pull and insert form fields, but that's beyond my PHP skills at the moment.

Thanks!

  • 写回答

1条回答 默认 最新

  • duanke6057 2015-02-04 17:15
    关注

    I had the same issues once upon a time , there are 2 ways out:

    Greasemonkey:

    Greasemonkey is a Mozilla Firefox extension that allows users to install scripts that make on-the-fly changes to web page content after or before the page is loaded in the browser (also known as augmented browsing). The changes made to the web pages are executed every time the page is viewed, making them effectively permanent for the user running the script.

    It is available at: https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/

    Using firebug

    According to me the better solution is to use the firebug 'net' tab to capture the post sent when you fill up the form and repeat that post with Curl.

    function post($url,$data) { 
        $process = curl_init($url); 
        curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers); 
        curl_setopt($process, CURLOPT_HEADER, 1); 
        curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent); 
        if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file); 
        if ($this->cookies == TRUE) curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file); 
        curl_setopt($process, CURLOPT_ENCODING , $this->compression); 
        curl_setopt($process, CURLOPT_TIMEOUT, 30); 
        if ($this->proxy) curl_setopt($process, CURLOPT_PROXY, $this->proxy); 
        curl_setopt($process, CURLOPT_POSTFIELDS, $data); 
        curl_setopt($process, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1); 
        curl_setopt($process, CURLOPT_POST, 1); w
        $return = curl_exec($process); 
        curl_close($process); 
        return $return; 
    } 
    

    Sources:

    1) https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/

    2) Auto fill and submit forms on external site

    3) http://en.wikipedia.org/wiki/Greasemonkey

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

报告相同问题?

悬赏问题

  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 被蓝屏搞吐了,有偿求帮解答,Ai回复直接拉黑
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并