Reputation: 2036
I have a communication problem between home.php page and user.php page.
on Homepage there is link for Log out
<span class="log_out"> <a id="logOut">Log Out</a></span>
When a user click this page ajax call will be started
Here is my ajax call
<script>
$( document ).ready(function() {
$( "#logOut" ).click(function() {
$.ajax({
url: 'class/user.php',
data: "logout=1",
success: function(data) {
$('body').append(data);
}
});
});
});
in user.php I have this
<?php
if(isset($_GET['logout'])){
echo "alert";
$_SESSION['user'] = 0;
}
?>
When I click logout, alert is being appended in body, but session variable was not changed at all.
I dont know what's going on here.
Upvotes: 0
Views: 723
Reputation: 2036
if(isset($_GET['logout'])){
if(!isset($_SESSION))
{
session_start();
}
$_SESSION['user'] = 0;
Print_r ($_SESSION);
}
I found solution thanks for helping guys, I just need to add session validation on my if else clause, although I have this validation on top of the page, when I added it inside the function, problem fixed
Upvotes: 1
Reputation: 1338
You need to add session_start();
to the top of your user.php file and also debug with the echo after a session is set, otherwise you'll get the warning you're getting at the moment.
Upvotes: 1