No, wait, finally done it.
This isn't the most elegant way of doing things, but, hey - it works.
Okay, to get a javascript varible into a php variable:
1. Create a page with just head, body, and a form with hidden fields for whatever variables you want. Set the form attributes to point it at a seperate php page
Code: Select all
<form method="e;post"e; action="e;myphppage.php"e;>
2. In the head, put the JS code that gets the variables you need.
3. In the body, put an onload handler like the following:
Code: Select all
<body onLoad="e;document.formsї0].hiddenFieldName.value = getvariable('myJSVariable');"e;>
4. You can add several of these into one onload event, as long as they are seperated by semi-colons(;), thusly:
Code: Select all
<body onLoad="e;document.formsї0].hiddenFieldName.value = getvariable('myJSVariable'); document.formsї0].hiddenFieldNameB.value = getvariable('myJSVariableB');"e;>
5. Now, at the end of the onload event(before the last quote), add
6. That's it!
Here is a complete example page; lets say you wanted to send the users screen resolution to PHP...
Code: Select all
<html>
<head>
<script language="e;javascript"e;>
var width = screen.width;
var height = screen.height;
</script>
</head>
<body onload="e;document.formsї0].screenWidth.value = getvariable('width'); document.formsї0].screenHeight.value = getvariable('height'); document.formsї0].submit();"e;>
<form method="e;post"e; action="e;nextpage.php"e;>
<input type="e;hidden"e; name="e;screenWidth"e; value="e;"e;>
<input type="e;hidden"e; name="e;screenHeight"e; value="e;"e;>
</form>
</body>
</html>
From here, it should be pretty easy when you get to 'nextpage.php' to start manipulating the variables in PHP.
Phew!