php - Saving the login after refreshing the page

one text

Solution:

You are generating a username in the page but not storing it.

This is an example where I send the generated username via POST with a submit button and then use the php session to store the username for this user:

<?php
    session_start();
    if(isset($_POST['username'])) {
        $_SESSION['username'] = $_POST['username'];
    }

    if(isset($_SESSION['username'])) {
        $value = $_SESSION['username'];
    } else {
        $value = (strval(bin2hex(openssl_random_pseudo_bytes(1)))) . date("Y") .
        (strval(bin2hex(openssl_random_pseudo_bytes(1)))) . date("d") .
        (strval(bin2hex(openssl_random_pseudo_bytes(1)))) . date("m") .
        (strval(bin2hex(openssl_random_pseudo_bytes(1))));
    }
?>

<form action="" method="post">
    <label for="username">Ваш логін</label>
    <input type="text" name="username" value="<?php echo $value; ?>"
    readonly="readonly">
    <input type="submit" value="Save username">
</form>

After storing the username I make a simple if statement, if there is a username stored use that one, else generate a new one.

Source