简体   繁体   中英

cant login to another site with php CURL

im trying to login into " http://fourse.com/automation/Page/Login " and fetch 'new-support' page , But its not working ! and output result is just Login page... you can see the username and password , feel free to check the site structure-- i was trying 6 other CURL login examples but all fail. this is my last chance , my code is :

        /*  Login part of the code -- start */

        $cookie_file_path = getcwd() . '/cookie.txt';
        //Emulating Firefox Browser:
        $agent = $_SERVER['HTTP_USER_AGENT'];
        //First, get and write session cookie:
        $ch = curl_init(); 

        curl_setopt($ch, CURLOPT_URL,'http://fourse.com/automation/Page/Login');
        curl_setopt($ch, CURLOPT_USERAGENT, $agent);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
        curl_setopt($ch, CURLOPT_COOKIEJAR,  $cookie_file_path);

        $loginpage_html = curl_exec ($ch);

        curl_close ($ch);

        //Now, use the session cookie to actually log in:
        $POSTFIELDS = "username=esmaeili&password=183791";  

        $ch = curl_init(); 


        curl_setopt($ch, CURLOPT_URL,'http://fourse.com/automation/support/new-support');
        curl_setopt($ch, CURLOPT_USERAGENT, $agent);
        curl_setopt($ch, CURLOPT_POST, 1); 
        curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_REFERER, 'http://fourse.com/automation/support/new-support');
        curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
        curl_setopt($ch, CURLOPT_COOKIEJAR,  $cookie_file_path);

        $logon_result = curl_exec ($ch);
        curl_close ($ch);


        echo $logon_result;

您没有提交名为“登录”的表单的隐藏字段。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM