Array in array [help ! urgent]

Discussion in 'PHP' started by er1cw, Oct 7, 2006.

  1. #1
    Hi, I need a quick solution for my website traffic spike..

    I need my script to randomly pick an account to use:

    something like this

    $account[1]=dad
    $pass[1]=mum

    $account[2]=grandma
    $pass[2]=grandpa

    $account=$account[random]
    $pass=$pass[random]

    How is that possible ?
     
    er1cw, Oct 7, 2006 IP
  2. fireshark

    fireshark Peon

    Messages:
    190
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    last 2 vars have to have dirrerent names

    you will want to generate a random number
    round to say 3 decimal places
    do if number > 0 and .333 some other number = 1
    and so on
    and then do
    eval("$account_data = $account[" . $random2 . "];");
     
    fireshark, Oct 7, 2006 IP
  3. er1cw

    er1cw Peon

    Messages:
    114
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    erm.. y do i need decimal place ?
     
    er1cw, Oct 7, 2006 IP
  4. er1cw

    er1cw Peon

    Messages:
    114
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Will this work ?

    $acc[1]=
    $pass[1]=

    $acc[2]=
    $pass[2]=

    $random = rand(1, 2);
    $login = $acc[" .$random. "];
    $pass = $pass[" .$random. "];
     
    er1cw, Oct 7, 2006 IP
  5. coolsaint

    coolsaint Banned

    Messages:
    257
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #5
    My dear Friend er1cw,

    Why don't you run the script and get the answer whether it works or not? If it doesn't let us know. We will try to help.

    Thanks.

    Coolsaint.
     
    coolsaint, Oct 7, 2006 IP
  6. er1cw

    er1cw Peon

    Messages:
    114
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Nope. It doesnt work : (
     
    er1cw, Oct 7, 2006 IP
  7. er1cw

    er1cw Peon

    Messages:
    114
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Would like to clarify. I wish to made something like this

    $random= rand(1, 2);

    $account[1]=dad;
    $pass[1]=mum;

    $account[2]=grandma;
    $pass[2]=grandpa;

    $login=$account[1]; or $account[2]; ( depends on $random )
    $password=$pass[1]; or $pass[2]; ( depends on $random )

    if $login=$account[1], $password must be $pass[1]. And so on...

    how can i achieve that ?
     
    er1cw, Oct 7, 2006 IP
  8. rb3m

    rb3m Peon

    Messages:
    192
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #8
    $account[1]="dad";
    $pass[1]="mum";

    $account[2]="grandma";
    $pass[2]="grandpa";

    $use = rand(1,2);

    if ($loginname==$account[$use] and $loginpass==$pass[$use]) {
    ...
    }
     
    rb3m, Oct 8, 2006 IP
  9. er1cw

    er1cw Peon

    Messages:
    114
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thank you !
     
    er1cw, Oct 8, 2006 IP
  10. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #10
    It would probably be more appropriate to use the array_rand function.

    
    $accounts = array (); // Initialise to avoid code injection
    $accounts[] = array ('u' => 'mom', 'p' => 'momspassword');
    $accounts[] = array ('u' => 'dad', 'p' => 'dadspassword');
    $accounts[] = array ('u' => 'grammma', 'p' => 'herpassword');
    
    $account_index = array_rand ($accounts);
    
    list ($username, $password) = $accounts[$account_index];
    
    // Now use the $username adn $password variable here
    
    PHP:
     
    exam, Oct 9, 2006 IP