How to recreate a PHP session without loaning the user

Asked

Viewed 58 times

-3

It is possible to recreate a $_SESSION in PHP without dislocating the user?

I have a restricted area where he can update some of his information in the database.

The problem is that when he logs in I create some sessions to use this information during his browsing. For example, his photo ($fotoUser = $_SESSION['fotoUser'];), the path of this photo is recorded in the database, and when it updates it, I update the path in the database and delete the old image in the folder to avoid accumulating images that are not being used, until then everything working right.

The problem is that after he updates the photo or some given as his name, if he gives a CRTL+F5 or even F5 to refresh the page, the photo simply becomes null, because the path in it is from SESSION created at login time, so it does not take the new image. It has to recreate the session without undoing it, or some different alternative?

1 answer

0

It’s quite simple, you remove the session and create another, within the image upload function.

// Amrazena a imagem antiga para você poder deletar da pasta;
$imagemantiga = $_SESSION['fotoUser'];

// Remove a sessão $_SESSION['fotoUser']
unset($_SESSION['fotoUser']);

//Recria com um novo valor.
$_SESSION['fotoUser'] = "novafoto do usuario"

Do this for the $_SESSION that it needs, except for the one that keeps the user logged in. NOTE: I don’t know if to load this data by $_SESSION be a good idea.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.