Sasuke Scend Sasuke Scend - 3 months ago 9
HTML Question

session destroy in log-in and disable back

I have 4 files home.php, log_out.php, blank_one.php, connection.php
and did not include the login.php and index.php since it only reads the
user name and password.

My problem is the session after clicking the log out


then click arrow back


to go blank_one.php directly I get these errors :'(


  • Notice: Undefined index: CurrentUser

  • Notice: Undefined index: CurrentUserType

  • BLANK ONE



========================================================================

and since logout(log_out.php) was clicked the content must be no user found ,EMPTY and back should be disabled.

Is there a way to handle this sessions to remove the errors after destroying it ?

`help please. :'(

blank_one.php


<?php
session_start();
$currUser = $_SESSION["CurrentUser"];
$currUserType = $_SESSION["CurrentUserType"];
echo('BLANK ONE');
?>





home.php


<?php
session_start();
$currUser = $_SESSION["CurrentUser"];
$currUserType = $_SESSION["CurrentUserType"];
if($currUserType == '1' or $currUserType == '2')
{
echo '
<html>
<body>
<a href="blank_one.php">blank</a>
<a href="log_out.php">logout</a>

</body>
</html>
';

}

else if($currUserType == '2'){

}

else if($currUserType == '3'){
echo '

';

}else{
echo '<div> no user found </div>';


}

?>





connection.php


<?php
$conn = mysql_connect('localhost', 'root', '', 'life');

if (!$conn)
{
die('Connect Error: ' . mysql_errno());
session_destroy();
session_start();
}

else
{
//echo ("connected from connection.php");
session_start();
echo ("");
}
?>





log_out.php


<?php
session_start();
include('connection.php');
$conn = mysql_connect('localhost', 'root', '', 'wildlife');

if ($conn)
{
$update=mysql_query("INSERT INTO wrd_user(emp_log_out) VALUES (now())");
session_destroy();
mysql_close();
header('Location:index.php');
}
else
{

echo ("");
}


?>




Answer

Wrap your variable setting code in blank_one.php will solve the problem:

<?php
session_start();
if (isset($_SESSION["CurrentUser"])) {
    $currUser = $_SESSION["CurrentUser"];
}
if (isset($_SESSION["CurrentUserType"])) {
    $currUserType = $_SESSION["CurrentUserType"];
}
echo('BLANK ONE');
?>

You need the same in home.php too.