1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

php how can set counter limit?

Discussion in 'PHP & Perl' started by livorno87, Dec 8, 2015.

  1. livorno87

    livorno87 Newbie

    Joined:
    Jan 6, 2015
    Messages:
    19
    Likes Received:
    2
    Hi i have a code. I want to stop when (example) 11 result. how can i stop curl when script count 11 result? i want to set result limit
    Code:
    <?php
    class instaAuth
    {
        public function _userlistesi() {
            $klasor = opendir("cookieboq/");
            while(false !== ($veriler = readdir($klasor))) {
                if(strstr($veriler,'txt')) {
                $bir_veri = str_replace('.txt','',$veriler);
                $user_ekle .= "$bir_veri,";
            }
        }
        $userler = substr($user_ekle,0,-1);
        $users_arr = explode(",",$userler); 
        return $users_arr;
        }
    
    public function _authLike($_ID,$userlist, $DELETE = NULL)
        { 
            if ( !empty($userlist) )
            {
                $type = ($DELETE == TRUE) ? 'unlike' : 'like';
    
                $members = array();
                $params = array();
                foreach ( $userlist as $username )
                {
                    $_cookie = $this->_cookieFolder . $username . $this->_cookieExtension;
                    $randomProxy = ( count($this->_proxy) > 0 ) ? $this->_proxy[rand(0, (count($this->_proxy) - 1))] : NULL;
    
                    if ( !file_exists($_cookie) )
                    {
                        continue;
                    }
                    $members[] = $username;
                    $fake_ip = $this->fakeIP();
                    $header = array(
                        "Accept: */*",
                        "Accept-Language: tr;q=1",
                        "HTTP_CLIENT_IP"        => $fake_ip,
                        "HTTP_FORWARDED"        => $fake_ip,
                        "HTTP_PRAGMA"           => $fake_ip,
                        "HTTP_XONNECTION"       => $fake_ip,);
    
                    $options = array(
                        CURLOPT_POST => TRUE,
                        CURLOPT_POSTFIELDS => $this->signed(json_encode(array())),
                        CURLOPT_HTTPHEADER => $header,
                        CURLOPT_COOKIEJAR => $_cookie,
                        CURLOPT_COOKIEFILE => $_cookie,
                        CURLOPT_USERAGENT => $this->_useragent,
                    );
    
                    $params[] = array(
                        'url' => "deneme/",
                        'options' => $options
                    );
                }
            } else {
                throw new Exception('Error: _authLike() - Be&#287;eni yapt&#305;rabilmeniz i├žin {cookies} tan&#305;mlamal&#305;s&#305;n&#305;z.');
            }   
            $multiCURL = new \RollingCurl\RollingCurl();
            foreach ($params as $param) {
                $request = new \RollingCurl\Request($param['url'], 'POST');
                $request->setOptions($param['options']);
                $multiCURL->add($request);
            }
    
            $this->_result = 0;
            $multiCURL
                ->setCallback(function(\RollingCurl\Request $request, \RollingCurl\RollingCurl $rollingCurl) {
    
                    $result = $request->getResponseText();
                    if ( is_string($result) )
                    {
                        $result = json_decode($result);
                        if ( is_object($result) )
                        {
                            if ($result->status == 'ok') $this->_result++;
                        }
                    }
                })
                ->setSimultaneousLimit(100)
                ->execute()
            ;
    
            $result = array(
                'success' => $this->_result,
                'errors' => NULL
            );
    
            return json_decode(json_encode($result));
    
        }
    }
    and this insterested other code page

    Code:
    <form action="" method="POST">
    
    Pictures ID : <input type="text" name="apifotoId">
    <br>
    Limits : <input type="text" name="limit">
    <br>
    <input type="submit" value="Like Send">
    </form>
    <?php
    include("class.php")
    if(isset($_POST['apifotoId'])) {
    $start = time();
    $y = new instaAuth(); 
    $user_list = $y->_userlistesi();
    $limit = $_POST["limit"];
    $_ID = $_POST['apifotoId'];
    $y->_authLike($_ID,$user_list);
    
    $fark = round(time()-$start)/60;
    echo "Likes Complete (".$fark." dk.)"; 
    
    }
    
    ?>
     
  2. roadhamster

    roadhamster Regular Member

    Joined:
    Mar 12, 2012
    Messages:
    335
    Likes Received:
    242
    Code:
    $result = $request->getResponseText();
                    if ( is_string($result) )
                    {
                        $result = json_decode($result);
                        if ( is_object($result) )
                        {
                            if ($result->status == 'ok') $this->_result++;
                            [COLOR=#ff0000]if ($this->_result > 11) exit();[/COLOR]
                
                }
                    }
    
    Maybe the code in red would do the trick.
     
    • Thanks Thanks x 1
  3. bartosimpsonio

    bartosimpsonio Jr. VIP Jr. VIP Premium Member

    Joined:
    Mar 21, 2013
    Messages:
    12,081
    Likes Received:
    10,845
    Occupation:
    WHEREZ MA
    Location:
    BITCOINS AT?
    Home Page:
    This works but it'll exit the script and everything that comes after it. If you want to continue doing something else below, just use break instead of exit()

    if ($this->_result > 11) break;
     
  4. ChanzGrande

    ChanzGrande Elite Member

    Joined:
    Feb 16, 2008
    Messages:
    2,484
    Likes Received:
    1,173
    Occupation:
    Accountant
    Location:
    Northern Woods Counting Money
    Wish there was some code commenting here. lol. Looks like you are coding a great application or working with a decently coded one for accomplishing a like of what? Clearly looks like a fb or youtube oriented script. Way to go.
     
  5. livorno87

    livorno87 Newbie

    Joined:
    Jan 6, 2015
    Messages:
    19
    Likes Received:
    2
    not solve my problem. anybody php coder can help me on teamviewer? my skype: alejandro23244