john john - 11 months ago 30
PHP Question

get contents of javascript value into a php variable?

i have a client who is required to use specific tracking that is only made available through javascript. he wants to be able to capture the exact same information being printed on the client side.

how can i add this into the existing php script to add the data into the database? my only idea was to echo the javascript directly inside the main script, but i can't seem to figure out how to get the values out of the php echo.

any ideas?


You can send it to the server using a dummy image.

document.write('<img src="file.php?foo=value1?bar=value2&...">');

contents of file.php

Header("Content-type: image/png"); 

do something with $_GET['foo']


It's not the best way, but it's fast and it will work.