PHP Curl login with redirect not working

后端 未结 3 1421
無奈伤痛
無奈伤痛 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);
    }
    

提交回复
热议问题