title: Setting SESSION variable in PHP
body: <p>Page1.php has a variable "flag" with value=1. When clicked, the javascript function "ajaxreq()" is called, and a text "Click me" appears below (ajax request from page2.php).</p>
  
  <p>When clicked upon the appeared "click me", it calls "ajaxreq2(3)", and displays the text message "success". On clicking upon the displayed text message "success", the div content( id : displayLater) is set to display, which was hidden till now. This div has to contain the updated value of $_SESSION['tag'] in the $flag variable. How can i update it?</p>
  
  <p>In this code, it gives out error : "undefined index 'tag' in page1.php".</p>
  
  <p>In order to make use of the variable $_SESSION['tag'], I have to reload page1.php everytime. Otherwise, it remains uninitialized.
  Is there a possibility that I can use the updated variable in page1.php?</p>
  
  <p>page1.php</p>
  
  <pre><code>&lt;?php
  session_start();
  $flag=1;
  echo "&lt;span onclick='ajaxreq()'&gt;$flag&lt;/span&gt;";
  ?&gt;
  
  &lt;div id="page2contents"&gt;&lt;/div&gt;
  
  &lt;div id="displayLater" style="display:none"&gt;
    &lt;span&gt;This is done.&lt;/span&gt;
    &lt;?php
     if(isset($_SESSION['tag']))
       $flag=$_SESSION['tag'];
    ?&gt;
    &lt;span onclick="displayNow($flag)"&gt;$flag&lt;/span&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>page2.php</p>
  
  <pre><code>&lt;?php
  echo "&lt;div onclick='ajaxreq2(3)'&gt;Click me&lt;/div&gt;";
  ?&gt;
  &lt;div id="page3contents.php"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>page3.php</p>
  
  <pre><code>&lt;?php
  session_start();
  $tag=$_POST['tagger'];
  $_SESSION['tag']=$tag;
  echo "&lt;span onclick='displayNow($tag)'&gt;success&lt;/span&gt;";
  ?&gt;
  </code></pre>
  
  <p>JAVASCRIPT functions are as follows:</p>
  
  <pre><code>function ajaxreq()
  {
    $("#page2contents").load("page2.php");
  }
  
  function ajaxreq2(x)
  {
    $("#page3contents").load("page3.php",{tagger:x});
  }
  
  function displayNow(abc)
  {
    abc=abc+2;    //some operation on abc
    $("#somethingToDisplay").show();   //displaying something else
  }
  </code></pre>