Instagram-php-scraper: Using $this when not in object context

Created on 21 Dec 2018  路  4Comments  路  Source: postaddictme/instagram-php-scraper

You are using $this->userSession['csrftoken'] in the Instagram::parseCookies() method.

    /**
     * We work only on https in this case if we have same cookies on Secure and not - we will choice Secure cookie
     *
     * @param array $headers
     *
     * @return array
     */
    private static function parseCookies($headers)
    {
        $rawCookies = isset($headers['Set-Cookie']) ? $headers['Set-Cookie'] : isset($headers['set-cookie']) ? $headers['set-cookie'] : [];

        if (!is_array($rawCookies)) {
            $rawCookies = [$rawCookies];
        }

        $not_secure_cookies = [];
        $secure_cookies = [];

        foreach ($rawCookies as $cookie) {
            $cookie_array = 'not_secure_cookies';
            $cookie_parts = explode(';', $cookie);
            foreach ($cookie_parts as $cookie_part) {
                if (trim($cookie_part) == 'Secure') {
                    $cookie_array = 'secure_cookies';
                    break;
                }
            }
            $value = array_shift($cookie_parts);
            $parts = explode('=', $value);
            if (sizeof($parts) >= 2 && !is_null($parts[1])) {
                ${$cookie_array}[$parts[0]] = $parts[1];
            }
        }

        $cookies = $secure_cookies + $not_secure_cookies;

        if (isset($cookies['csrftoken'])) {
            $this->userSession['csrftoken'] = $cookies['csrftoken'];
        }

        return $cookies;
    }

Most helpful comment

hi, a solution for $headers['set-cookie'] and @congkv problems :

Instagram.php:688
`
//$rawCookies = isset($headers['Set-Cookie']) ? $headers['Set-Cookie'] : isset($headers['set-cookie']) ? $headers['set-cookie'] : [];
IF ( IsSet($headers['Set-Cookie']) ) {
$rawCookies = $headers['Set-Cookie'];
} ElseIF ( IsSet($headers['set-cookie']) ) {
$rawCookies = $headers['set-cookie'];
} Else {
$rawCookies = [];
}


//$this->userSession['csrftoken'] = $cookies['csrftoken'];
$instance->userSession['csrftoken'] = $cookies['csrftoken'];
`

All 4 comments

Since parseCookies is a static method the $this variable is not available in its scope. We need to remove it..

hi, a solution for $headers['set-cookie'] and @congkv problems :

Instagram.php:688
`
//$rawCookies = isset($headers['Set-Cookie']) ? $headers['Set-Cookie'] : isset($headers['set-cookie']) ? $headers['set-cookie'] : [];
IF ( IsSet($headers['Set-Cookie']) ) {
$rawCookies = $headers['Set-Cookie'];
} ElseIF ( IsSet($headers['set-cookie']) ) {
$rawCookies = $headers['set-cookie'];
} Else {
$rawCookies = [];
}


//$this->userSession['csrftoken'] = $cookies['csrftoken'];
$instance->userSession['csrftoken'] = $cookies['csrftoken'];
`

@Parviz-Turk

hi, a solution for $headers['set-cookie'] and @congkv problems :

it is trash, not a solution... where there $instance?

@raiym can be closed :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

juangrimm picture juangrimm  路  8Comments

eelcol picture eelcol  路  5Comments

FranciscoG picture FranciscoG  路  6Comments

joty0 picture joty0  路  3Comments

jakerator picture jakerator  路  5Comments