Jump to content

Can't increase vars in code [HELP]


Lautarox

Recommended Posts

Im having a really strange problem, it's like if the $inc var isn't increasing, like if it wasn't recognised cause, Codigo prints ' ', whats happening? im using php in console, but i don't think that's the problem, i also made a function to increase this var, but it doesn't work either..

Thanks

 

<?

$inc = 7374458;
$url = "***************";
$codigo = "M".$inc;

function increase() {
$inc += 1;
}

function get_web_page($url, $method) {
if($method == 0) { 
$postfields = '****=mobile&******='.$codigo.'';
$url = "************************";
}
else {
$postfields = 'u_name='.$argv[0].'&p_word='.$argv[1].'';
         $url = "**********";
}

    $options = array(
        CURLOPT_RETURNTRANSFER => true,     // return web page
        CURLOPT_HEADER         => false,    // don't return headers
        CURLOPT_FOLLOWLOCATION => true,     // follow redirects
        CURLOPT_ENCODING       => "",       // handle all encodings
        CURLOPT_USERAGENT      => "spider", // who am i
        CURLOPT_AUTOREFERER    => true,     // set referer on redirect
        CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
        CURLOPT_TIMEOUT        => 120,      // timeout on response
        CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
        CURLOPT_POST           => 2,
        CURLOPT_POSTFIELDS     => "$postfields"
    );

    $ch      = curl_init($url);
    curl_setopt_array($ch, $options);
    $content = curl_exec($ch);
    $err     = curl_errno($ch);
    $errmsg  = curl_error($ch);
    $header  = curl_getinfo($ch);
    curl_close($ch);

    if($method != 0) {
    $test = ereg("You must log in to access this page.", $content, $matches);
      if(!$test) {
        echo "Se ha logueado satisfactoriamente,  \n";
        $nextmethod = 0;
      }
      else {
        die('No se pudo loguear correctamente '.$argv[0].' , '.$argv[1].'');
      }
    }
    else {
     $test = ereg("Thank you", $content, $matches);
     if($test) {
       $completed = 1;
       echo ", usuario: '$argv[0]' password: '$argv[1]' con el code: '$codigo'";
     }
     else {
     increase();
     echo "Codigo: '$codigo' \n";
     $nextmethod = 0;
     }
    }
}
get_web_page($url, 1);

do {
get_web_page($url, $nextmethod);
}
while($completed = 1);

?>

Link to comment
https://forums.phpfreaks.com/topic/114882-cant-increase-vars-in-code-help/
Share on other sites

You're setting $codigo at the start of the script. It will never change.

 

As for the function, you need to return the new value. Don't use the global statement.

<?php

$inc = 7374458;
$url = "***************";
$codigo = "M".$inc;

function increase($inc) {
  return(++$inc);
}

function get_web_page($url, $method) {
if($method == 0) { 
$postfields = '****=mobile&******='.$codigo.'';
$url = "************************";
}
else {
$postfields = 'u_name='.$argv[0].'&p_word='.$argv[1].'';
         $url = "**********";
}

    $options = array(
        CURLOPT_RETURNTRANSFER => true,     // return web page
        CURLOPT_HEADER         => false,    // don't return headers
        CURLOPT_FOLLOWLOCATION => true,     // follow redirects
        CURLOPT_ENCODING       => "",       // handle all encodings
        CURLOPT_USERAGENT      => "spider", // who am i
        CURLOPT_AUTOREFERER    => true,     // set referer on redirect
        CURLOPT_CONNECTTIMEOUT => 120,      // timeout on connect
        CURLOPT_TIMEOUT        => 120,      // timeout on response
        CURLOPT_MAXREDIRS      => 10,       // stop after 10 redirects
        CURLOPT_POST           => 2,
        CURLOPT_POSTFIELDS     => "$postfields"
    );

    $ch      = curl_init($url);
    curl_setopt_array($ch, $options);
    $content = curl_exec($ch);
    $err     = curl_errno($ch);
    $errmsg  = curl_error($ch);
    $header  = curl_getinfo($ch);
    curl_close($ch);

    if($method != 0) {
    $test = ereg("You must log in to access this page.", $content, $matches);
      if(!$test) {
        echo "Se ha logueado satisfactoriamente,  \n";
        $nextmethod = 0;
      }
      else {
        die('No se pudo loguear correctamente '.$argv[0].' , '.$argv[1].'');
      }
    }
    else {
     $test = ereg("Thank you", $content, $matches);
     if($test) {
       $completed = 1;
       echo ", usuario: '$argv[0]' password: '$argv[1]' con el code: '$codigo'";
     }
     else {
     $inc++;
     $codigo = 'M' . $inc;
     echo "Codigo: '$codigo' \n";
     $nextmethod = 0;
     }
    }
}
get_web_page($url, 1);

do {
get_web_page($url, $nextmethod);
}
while($completed = 1);

?>

 

But, why use a function at all, just increment $inc inline.

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.