Trigger PHP with javascript -


i have php process get's user's ip address, page on, screen resolution , date/time on website.

i want put line of code on other website such as:

<script type="text/javascript" src="http://www.mywebsite.com/tracker.js"></script> 

in javascript file, post information file called tracker.php processes information put in database.

i assume you're asking how send asynchronous request tracker.php, aka ajax. w3 schools has guide on here: http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp

the ip address , date/time can gotten without passing information down website. if want pass information such page on , resolution of viewing area, 1 easy way pass url variables.

xmlhttp=new xmlhttprequest(); xmlhttp.open("get","tracker.php?windowwidth=" + window.innerwidth +"&windowheight=" + window.innerheight + "&page=" + encodeuricomponent(document.url) ,true); xmlhttp.send(); 

these variables loaded tracker.php array $_get

$width = $_get["windowwidth"]; $height = $_get["windowheight"]; $page = $_get["windowpage"]; 

there more elegant solutions, such $_post allows far more information passed down in single request, or 1x1 tracking images. page on can acquired using $_server["http_referer"] on tracker.php.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -