Error in indicies while unsetting Sessions

24 views Asked by At

While unsetting the session I am getting the error:

Undefined Index

I have used 3 files: set.php unset.php and view.php

I am new to PHP programming. Please Help!

1. set.php:

<?php
session_start();

$_SESSION['username'] = 'ayusch';

?>

2.unset.php
<?php
session_start();

unset($_SESSION['username']);

?>

3. view.php:
<?php

session_start();
echo 'Welcome  ' . $_SESSION['username'] . 'you are ' . $_SESSION['age'];

?>
1

There are 1 answers

2
Qaisar Satti On
2.unset.php
<?php
session_start();

unset($_SESSION['username']);

?>

change to this

2.unset.php
<?php
session_start();
session_unset();
session_destroy();

?>

read this link for unset session