How to get a random string in php programming?


You can use session id to geenrate random string

<?php
session_start();
echo session_id();
?>

2 Responses to “How to get a random string in php programming?”

  • Emissary says:

    Do you mean how to pick a random string out of a predetermined set?
    … put them in an array and use the array_rand() function:

    <?php

    $myStrings = array("Neo", "Morpheus", "Trinity");
    echo $myStrings[array_rand($myStrings, 1)];

    ?>
    References :

  • Roger Ranatuna says:

    You can use session id to geenrate random string

    <?php
    session_start();
    echo session_id();
    ?>
    References :

Leave a Reply