Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. Intitialize a session variable after onclick event is fired

Intitialize a session variable after onclick event is fired

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
phpcomtutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pandu web dev
    wrote on last edited by
    #1

    i want to initialize a php session variable when user clicks on a link, using a php function or any other way. for example

    link

    K 1 Reply Last reply
    0
    • P pandu web dev

      i want to initialize a php session variable when user clicks on a link, using a php function or any other way. for example

      link

      K Offline
      K Offline
      Kaivan Alimohammadi
      wrote on last edited by
      #2

      u can use ajax. u must create a function in your javascript code that send ajax request to your php file and get response from that.

      function getXMLHttpRequest()
      {
      if (window.XMLHttpRequest) {
      return new window.XMLHttpRequest;
      }
      else {
      try {
      return new ActiveXObject("MSXML2.XMLHTTP.3.0");
      }
      catch(ex) {
      return null;
      }
      }
      }

      function do_somting(){
      xhr= getXMLHttpRequest();
      xhr.onreadystatechange=function()
      {

              if(xhr.readyState==4 && xhr.status==200)
              {
                  //get response here from php file with xhr.responseText;
                  
              }
          }
          xhr.open("GET","file.php",true);
          xhr.send(null); 
      

      }

      and in php file that contains php functions.

      P 1 Reply Last reply
      0
      • K Kaivan Alimohammadi

        u can use ajax. u must create a function in your javascript code that send ajax request to your php file and get response from that.

        function getXMLHttpRequest()
        {
        if (window.XMLHttpRequest) {
        return new window.XMLHttpRequest;
        }
        else {
        try {
        return new ActiveXObject("MSXML2.XMLHTTP.3.0");
        }
        catch(ex) {
        return null;
        }
        }
        }

        function do_somting(){
        xhr= getXMLHttpRequest();
        xhr.onreadystatechange=function()
        {

                if(xhr.readyState==4 && xhr.status==200)
                {
                    //get response here from php file with xhr.responseText;
                    
                }
            }
            xhr.open("GET","file.php",true);
            xhr.send(null); 
        

        }

        and in php file that contains php functions.

        P Offline
        P Offline
        pandu web dev
        wrote on last edited by
        #3

        thanks for help

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups