Jump to content

Warning: array_rand() [function.array-rand]


TheUnknown

Recommended Posts

Warning: array_rand() [function.array-rand]: Second argument has to be between 1 and the number of elements in the array in /home/nora/public_html/----/stumble/free_stumbler.php on line 52

 

Line 52 is

 

  $rand_keys = array_rand($users, $free_stumbles);

 

Any ideas>

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/109505-warning-array_rand-functionarray-rand/
Share on other sites

The warning message is very clear. The second argument, $free_stumbles in your case, can't be any larger than the number of elements in your array,  $users, and it must be greater than zero.

 

What's it's value?

 

Ken

 

 

not sure bud

 

Does this help

 

 

<?php
set_time_limit(0);
$tottags=0;
foreach($tags as $key => $value){
if ($value!="") { $tottags++; $tgs[$tottags]=$value; }
}
$totrevs=0;
foreach($review as $key => $value){
if ($value!="") { $totrevs++; $rws[$totrevs]=$value; }
}

$ip = $_SERVER['REMOTE_ADDR'];
$ma = date("Y-m-d");

include("Curl.class.php");
$curl =& new Curl();
$urlhttp = "http://".$url;

if ($_SESSION["string"]!=$userstring){
errormess("Invalid turing number");
} else {
if ((!$url) or (substr_count($url,"http://")>0)) { 
errormess("Invalid url");
} else {
if ((!$tottags) or (!$totrevs)){

  errormess("At least one review and tag required");
} else {
  
  $eredm = mysql_query("SELECT * FROM freestumbles WHERE fip='$ip' AND fdate='$ma'") or die(mysql_error());
  if (mysql_num_rows($eredm)>0){
   errormess("You have already used the free option today. Try out tomorrow or buy a PIN code");
  } else {
  

   $eredm = mysql_query("INSERT INTO freestumbles(fip,fdate) VALUES('$ip','$ma')") or die(mysql_error());



  // getting users  
  $handle = fopen('./userlist.txt','r');
  $i=1; $counter=1;
  while (!feof($handle)) {
   $cucc = fgets($handle);
   if (($i%3)==1) { $thisuser = $cucc; } 
   if (($i%3)==2) { $users[$thisuser]=$cucc;  }
   if (($i%3)==0) { $codes[$thisuser]=$cucc; $counter++;}
   $i++;
  }
  
  
  $rand_keys = array_rand($users, $free_stumbles);
  

  
  // main part
  for($j=0;$j<$free_stumbles;$j++){

$user = $rand_keys[$j];
$code = $codes[$user];
$pass = $users[$user];


$user = substr($user,0,strlen($user)-2);
$pass = substr($pass,0,strlen($pass)-2);
$code = substr($code,0,strlen($code)-2);


// generating tags
$t1 = rand(1,$tottags);
$t2 = rand(1,$tottags);
while (($t2==$t1) and ($tottags>=3)){
 $t2 = rand(1,$tottags);
}
$t3 = rand(1,$tottags);
while ((($t3==$t1) or ($t3==$t2)) and ($tottags>=3)){
 $t3 = rand(1,$tottags);
}

$tags = $tgs[$t1].",".$tgs[$t2].",".$tgs[$t3];

$rev = rand(1,$totrevs);
$review = $rws[$rev];
$review = stripslashes($review);

print("Logging it with user: <a href=\"http://$user.stumbleupon.com\" target=\"blank\">$user</a> ");

$page = $curl->get("http://www.stumbleupon.com/login.php?logout=1");

$page = $curl->post("http://www.stumbleupon.com/login.php", array(
	'username'   => $user,
	'password' => $pass,
	'Submit'    => 'Submit',
));

if ($err = $curl->getError()) {
	print($err);
}

if (substr_count($page,'Try online demo')>0){
	print("<font color=darkred>Error</font> "); 
} else {
	print("<font color=green>Success</font> Stumbling: ");
}
$xurl = urlencode($urlhttp);
$page = $curl->get("http://www.stumbleupon.com/rate.php?username=$code&password=$pass&rating=1&url=$xurl");

if (substr_count($page,'ERROR')>0){
	print("<font color=darkred>Error</font> "); 
} else {
	print("<font color=green>Success</font> Leaving review: ");
}
$page = $curl->get("http://www.stumbleupon.com/url/$url");
$page = htmlentities($page);
$pos = strpos($page, 'ftoken');
$start = $pos+25;
$ftoken = substr($page,$start,23);


$page = $curl->post("http://www.stumbleupon.com/url/$url",array(
	'url' => $urlhttp,
	'action' => 'new_review',
	'ftoken' => $ftoken,
	'newcomment' => $review,
	'tags' => $tags,
	'x' => '0',
	'y' => '0',
	'nodate' => 'checked',
));

print("<font color=green>Success</font><br /> ");

sleep(3);
}
  }
}
}
}

/*


*/

?>

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.