title: On click of button, check if user is logged in or not
body: <p>I have a button that is responsible for performing multiple task, and has lot of scripting for it. When this button</p>
  
  <pre><code>&lt;button type="submit" value="submit" name="submit" class="second_button"&gt;Negotiate&lt;/button&gt;
  </code></pre>
  
  <p>the script applied on this button is </p>
  
  <pre><code>&lt;script&gt;
  
  var startClock;
  var submitamt;
  var walkaway;
  var digits;
  
  $(function() {
    startClock = $('#startClock').on('click', onStart);
    submitamt = $('#submitamt').on('click', onSubmit);
    walkaway = $('#walkaway').on('click', onWalkAway);
    digits = $('#count span');
    beforeStart();
  });
  
  var onStart = function(e) {
    startClock.fadeOut(function() {
      startTimer();
      submitamt.fadeIn(function() {
        submitamt.trigger('click'); // fire click event on submit
      });
      walkaway.fadeIn();
    });
  };
  
  var onSubmit = function(e) {
    var txtbox = $('#txt').val();
    var hiddenTxt = $('#hidden').val();
    $.ajax({
      type: 'post',
      url: 'test2.php',
      dataType: 'json',
      data: {
        txt: txtbox,
        hidden: hiddenTxt
      },
      cache: false,
      success: function(returndata) {
  
           console.log(returndata[3]);
      // $('#proddisplay').html(returndata);
      },
      error: function() { 
        console.error('Failed to process ajax !');
      }
    });
  };
  
  var onWalkAway = function(e) {
    console.log('onWalkAway ...');
  };
  
  var counter;
  var timer;
  var startTimer = function() {
    counter = 120;
    timer = null;
    timer = setInterval(ticker, 1000);
  };
  
  var beforeStart = function() {
    digits.eq(0).text('2');
    digits.eq(2).text('0');
    digits.eq(3).text('0');
  };
  
  var ticker = function() {
    counter--;
    var t = (counter / 60) | 0; // it is round off
    digits.eq(0).text(t);
    t = ((counter % 60) / 10) | 0;
    digits.eq(2).text(t);
    t = (counter % 60) % 10;
    digits.eq(3).text(t);
    if (!counter) {
      clearInterval(timer);
      alert('Time out !');
      resetView();
    }
  };
  
  var resetView = function() {
    walkaway.fadeOut();
    submitamt.fadeOut(function() {
      beforeStart();
      startClock.fadeIn();
    });
  };
  &lt;/script&gt;
  </code></pre>
  
  <p>before this script executes i wish to check if the user is logged in or not, In normal php i use this code</p>
  
  <pre><code>&lt;?
  if (isset($_SESSION['loggedin']) &amp;&amp; $_SESSION['loggedin'] == true || isset($_SESSION['fb_logged_in']) &amp;&amp; $_SESSION['fb_logged_in'] == true )
      {?&gt;
          &lt;!--display message--&gt;
      &lt;?}?&gt;   
  </code></pre>
  
  <p>but i am not able to understand how to embed it with the script i wish to display a popup message if the user is not logged in and ask user to login first</p>