0

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.

5
  • Did you check this ? stackoverflow.com/a/10649019/1003917 Commented Apr 19, 2014 at 2:25
  • It's something about the IF in user.php Commented Apr 19, 2014 at 2:27
  • @ShankarDamodaran yeah I just added it, at least I am not getting session warning, but the problem is still here Commented Apr 19, 2014 at 2:29
  • @PoomrokcThe3years but when i click log out body is appending alert Commented Apr 19, 2014 at 2:29
  • Thanks for helping guys again I found the solution Commented Apr 19, 2014 at 2:34

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for helping but, it is already done in every page, I posted the answer bleow
1

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

1 Comment

I don't see any else here .. or did you just mean if ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.