Click to See Complete Forum and Search --> : Passing javascript variables to either PHP or CGI


boryev
10-18-2006, 09:17 PM
Hello!
I came across this script :

<script type="text/javascript">
var pageViewerID = "somenumbers";
var pageOwnerID = "somenumbers";
var pageViewerFName = "someone'sname";
var pageOwnerFName = "someone'sname";
var pandoraRegFlag = '-1';
var userHasBlog = 't';

var HbxTrackingEnabled = false;
</script>
Its taken from a social networking site where my profile is located! The pageViewerID and pageViewerFName would change everytime a different person views my profile! Now, my question is, how do I store/pass those pageViewerFName and pageViewerID variables to a PHP or CGI page so that the data would be stored and I could see who viewed my profile just by viewing the PHP / CGI page?

Please help me!
Thank you in advance!

agent_x91
10-19-2006, 05:03 AM
You could try using javascript to create a URL to which the variables are passed, eg. make javascript open a URL such as something.php?pageviewerid=34834&pageownerid=87434883.... etc.

scousesheriff
10-19-2006, 09:33 AM
You could use an XMLHttpRequest in your javascript to open the URL in the background. Making a call to the LogIt function below would accomplish this as long as the browser supported some form of XMLHttpRequest:


function createXMLHttpRequest( ) {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
try { return new XMLHttpRequest( ); } catch(e) {}
return null;
}
function LogIt(){
var xhr = createXMLHttpRequest( );
if(xhr){
xhr.onreadystatechange = function( ) {
if (xhr.readyState==4) { // Request is finished
if (xhr.status==200) {
//Success - take some action if you want to when successful
} else {
//Failure - take some action if you want to when the sending failed
}
}
}
url = "//localhost/loghit.php"; //Your php script address
url = "?pageViewerID="+pageViewerID;
url = "&pageOwnerID="+pageOwnerID;
xhr.open("GET", url, true);
xhr.send(null);
}
}


Is this all clear?

theRamones
10-20-2006, 02:57 AM
try to make all variables to be a hidden input type in body (form) of the html, like this :
<input type="hidden" name="pageViewerID" value="somenumbers">
<input type="hidden" name="pageOwnerID" value="somenumbers">
etc