session_destroy not destroying the session

Hello, I made a site and i added a logout button and when it is activated it will destroy the session taking away the [php]if ($_SESSION[‘loginSubmit’] == TRUE) {
$_SESSION[‘logoutbutton_fromindex’] = $logoutbutton;
echo ‘

Hello, ‘.$_SESSION[“hellouser”].’
’;
$logoutbutton = @$_POST[‘logoutFormButton’];
if ($logoutbutton==TRUE) {
session_destroy();
}
}[/php]
here is all the code
Index page (Main Page)
[php] <?php session_start(); if ($_SESSION['loginSubmit'] == TRUE) { $_SESSION['logoutbutton_fromindex'] = $logoutbutton; echo '
Hello, '.$_SESSION["hellouser"].'
'; $logoutbutton = @$_POST['logoutFormButton']; if ($logoutbutton==TRUE) { session_destroy(); } } ?> body{background-image:url("pvpbackground.png");}a:link{color:#F0FFFF;text-decoration:none;}a:visited{color:#F0FFFF;text-decoration:none;}.pvplogo1{position:absolute;top:5%;left:30%;}.menu1{width:32%;height:5%;background-color:#002929;position:absolute;top:20%;left:34%;border-radius:20%;}.registerlink{ position:absolute;top:29%;left:80%;}.hellousername{position:absolute;top:26%;left:45%;}.infolink{position:absolute;top:35%;left:55%;}.logoutForm{position:absolute;}.logoutForm{position:absolute;top:26.5%;left:54%;}
register/login info
[/php] Second page (Login Page) [php] <?php session_start(); $con = mysqli_connect('mysql.1freehosting.com', 'u297061460', 'test', 'u297061460');

if (mysqli_connect_errno()) {
echo"Erry While Trying To Connect To Database" . mysqli_connect_error();
}
$Username = @$_POST[‘lUsername’];
$Password = @$_POST[‘lPassword’];
$submit = @$_POST[‘lsubmit’];
if ($submit==TRUE) {
if ($Password==TRUE) {
if ($Username==TRUE) {
$li = “SELECT * FROM pvptk WHERE username = ‘$Username’ AND password = ‘$Password’ LIMIT 1”;
$res = mysqli_query($con, $li);
if (mysqli_num_rows($res) == 1) {
$_SESSION[‘loginSubmit’] = $submit;
$_SESSION[‘hellouser’] = $Username;
if ($_SESSION[‘logoutbutton_fromindex’]==TRUE) {
session_destroy();
}
}
}
}
}
?>

body{background-image:url("pvpbackground.png");}a:link{color:#F0FFFF;text-decoration:none;}a:visited{color:#F0FFFF;text-decoration:none;0}.pvplogo1{position:absolute;top:5%;left:30%;}.menu1{width:32%;height:5%;background-color:#002929;position:absolute;top:20%;left:34%;border-radius:20%;}.registerlink{position:absolute;top:29%;left:80%;}.registerform{position:absolute;top:33%;left:43%;}
register/login
Username:
Password:
main [/php]

It doesn’t look like you’re doing anything after session_destroy(); You will need to either refresh the page or redirect them to a different page as the session variables are still on the page the user is on (but won’t be on the next page).

Another way you could do it would be to clear the value of the session before destroying it. I always check to make sure the session is set and has a value (not empty) before authenticating.

it still displays Hello, (There username)

This is how I do it:
[php] // Clear the session data:
$_SESSION = array();

// Clear the cookie:
setcookie(session_name(), false, time()-3600);

// Destroy the session data:
session_destroy();[/php]

its still displaying the Hello, user here is what i added[php]

<?php session_start(); if ($_SESSION['loginSubmit'] == TRUE) { $_SESSION['logoutbutton_fromindex'] = $logoutbutton; echo '
Hello, '.$_SESSION["hellouser"].'
'; $logoutbutton = @$_POST['logoutFormButton']; if ($logoutbutton==TRUE) { $_SESSION = array(); setcookie(session_name(), false, time()-3600); session_destroy(); } } ?> body{background-image:url("pvpbackground.png");}a:link{color:#F0FFFF;text-decoration:none;}a:visited{color:#F0FFFF;text-decoration:none;}.pvplogo1{position:absolute;top:5%;left:30%;}.menu1{width:32%;height:5%;background-color:#002929;position:absolute;top:20%;left:34%;border-radius:20%;}.registerlink{ position:absolute;top:29%;left:80%;}.hellousername{position:absolute;top:26%;left:45%;}.infolink{position:absolute;top:35%;left:55%;}.logoutForm{position:absolute;}.logoutForm{position:absolute;top:26.5%;left:54%;}
register/login info
[/php]sorry im kind of new at this

im sorry i forgot to add a method i feel dumb now :confused:

Sponsor our Newsletter | Privacy Policy | Terms of Service