PHP Curl login with redirect not working

后端 未结 3 1422
無奈伤痛
無奈伤痛 2020-12-22 04:48

I have the following PHP script which should get the content of a page, that is behind a login-form.

It is working fine on my localhost server, but it doesn\'t work

相关标签:
3条回答
  • 2020-12-22 05:37

    I solved it by first checking if open_basedir is set. If that is the case: the script first executes curl_exec() to set the cookies and then executes it again to get the hidden page. Parameters like op and form_build_id aren't used at all :P

    Code:

    if (ini_get('open_basedir') == '') {
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
    
        $postResult = curl_exec($ch);
        curl_close($ch);
    } else {
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
        curl_exec($ch);
        $postResult = curl_exec($ch);
    }
    
    0 讨论(0)
  • 2020-12-22 05:39

    form_build_id and CURLOPT_REFERER is missing You are suppose to send something like

     name=user&pass=pass&op=Inloggen&form_build_id=form-fc3c69bda9d4a9a4a53e70f836ece383&form_id=login_block_login_form
    
    0 讨论(0)
  • 2020-12-22 05:49

    Try adding the FOLLOWLOCATION option so it follows the redirect it's getting:

    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    
    0 讨论(0)
提交回复
热议问题