Generar strings aleatorios en PHP

Muchas veces, sobretodo para temas de generación de passwords, nos vemos obligados a generar strings aleatorios en nuestras aplicaciones PHP, para ello os dejamos la siguiente función:

function RandomString($len){
    $randstr = '';
    srand((double)microtime()*1000000);
    for($i=0;$i<$len;$i++){
        $n = rand(48,120);
        while (($n >= 58 && $n <= 64) || ($n >= 91 && $n <= 96)){
            $n = rand(48,120);
        }
        $randstr .= chr($n);
    }
    return $randstr;
}

 

148 responses to “Generar strings aleatorios en PHP

  1. Quyen

    It is appropriate time to make some plans for the future and it is time to be happy. I have read this post and if I could I want to suggest you few interesting things or advice. Maybe you can write next articles referring to this article. I desire to read more things about it!

  2. Lon

    Good post. I learn something new and challenging on websites I stumbleupon everyday. It will always be helpful to read content from other writers and use something from their sites.

  3. Garrett- India

    Thanks on your marvelous posting! I genuinely enjoyed reading it, you will be a great author. I will make certain to bookmark your blog and definitely will come back in the foreseeable future. I want to encourage you continue your great posts, have a nice holiday weekend!|

  4. Winfred

    thanx for this article: I’m composing a presentation I am in the middle of struggling with, and I’ve been searching for text similar to this. Very helpful!

  5. Hildred Chiropractic

    It’s perfect time to make some plans for the future and it’s time to be happy. I have read this post and if I could I desire to suggest you some interesting things or tips. Perhaps you can write next articles referring to this article. I want to read more things about it!

  6. Terrence Chiropractic

    Hey, I think your website might be having browser compatibility issues. When I look at your blog in Ie, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, great blog!

Deja una respuesta

Tu dirección de correo electrónico no será publicada.

Rúa Pilar Miró n 6 Santiago de Compostela

Jersey St , Manchester, Greater Manchester M4 6JG, GB

T. 609 538 171 - 634 59 34 43

info@teslatechnologies.com