Passing Javascript Varaibles to Php

Discussion in 'PHP' started by Freewebspace, Apr 29, 2008.

  1. #1
    This is only for files under the same server or same website

    Aim:To pass document.referrer variable to Php and to write the referrer variable on a text file;

    First let us create two file called 1a.html and 2a.html

    1a.html will contain a link to 2a.html

    and 2a.html will contain just two javascript calls one will call a file called xml1.js

    Files used 1a.html,2a.html,xml1.js,78.php and ip1.txt

    Here is the source of 1a.html

    Source of 2a.html

    Here First we are calling xml.js javascript and then calling change1() function in it
    Source of xml1.js

    In the above function function GetXmlHttpObject() is nothing but creating Xmlhttpobject by which get function will be routed (AJAX).Do n’t worry about that if you need to more about there go to http://www.w3schools.com/ajax/ajax_source.asp.


    Now let us go to the second line ,Here we are declaring change1 function and then we checking whether browser supports xml if not browser will display an error message indicating that “your Browser does n’t support AJAX”

    Now let me explain what these four lines contain



    The php file(78.php is like this


    by this you can pass variables to a php script and from php you can insert any data into your database;



    I hope this tutorial is helpful for others I have also written it in my blog

    Remember this above one does n't uses location.href to redirect to a php page to pass varaibles like others
     
    Freewebspace, Apr 29, 2008 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,901
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    sarahk, Apr 29, 2008 IP
  3. Freewebspace

    Freewebspace Notable Member

    Messages:
    6,213
    Likes Received:
    370
    Best Answers:
    0
    Trophy Points:
    275
    #3
    Freewebspace, Apr 29, 2008 IP