John Davidson

html - Change profile picture while log out PHP

0 comments
Message:


on my app when user log out, there is a redirection to login page and email is unset but I also want to unset the profile picture because right now when user is redirect to login page it display his profile picture even though he's log out. I want to display default picture which is './assets/profile-picture/avatar.jpg'


The code looks like that:


<?php
session_start();
unset($_SESSION['email']);
$_SESSION['profileImage'] = './assets/profile-picture/avatar.jpg';
// unset ($_SESSION['profileImage']);

header("Location: login.php");

exit;
?>






<img src=<?php echo isset($user['profileImage']) ? $user['profileImage']: "./assets/profile-picture/avatar.jpg" ; ?> style="width: 200px; height: 200px" class="img rounded-circle" alt="profile">

I also try unset which is comment but none of that worked. Thanks for any clue.



My Answer:
php
session_start();

// Unset email
unset($_SESSION['email']);

// Unset profile picture
unset($_SESSION['profile_picture']);

// Redirect to login page
header("Location: login.php");
exit();
?>


In this code, I added `unset($_SESSION['profile_picture']);` to unset the profile picture when the user logs out. This will ensure that the default picture is displayed when the user is redirected to the login page.

Rate this post

5 of 5 based on 9705 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us