In php I am trying to get screen resolution of website visitor by 2 different javascript commands. $width = "<script>var windowWidth = screen.width; document.writeln(windowWidth); </script>"; $height = "<script>var windowHeight = screen.height; document.writeln(windowHeight); </script>"; AND $width = "<script>document.write(screen.width);</script>"; $height = "<script>document.write(screen.height);</script>"; $screenres = $width." x ".$height; When I echo $screenres variable in php I get correct screen resolution but when I try to save this variable in sql database then "<script>d" is saved instead of actual variable of this variable. Any help? MI6
It's not clear how you're getting any information back to the server to save - is there a form somewhere? If you are using a form add a hidden input to it and use javascript to set the value. If it's not a form, then use an ajax call to send the information you need saved down to a php script on the server. Javascript can't save to your database.
Thanks for replying. As I mentioned before I am trying to save website visitor data like os, browser, referral url, resolution, etc in sql database. Following php code works fine if I display resolution on page. <? // $width = "<script>var windowWidth = screen.width; document.writeln(windowWidth); </script>"; // $height = "<script>var windowHeight = screen.height; document.writeln(windowHeight); </script>"; $screenres = $width." x ".$height; echo $screenres; // It means screen resolution value "1366 x 768" in passed from javascript to php variable "$screenres". ?> PHP: But when I save this variable $screenres into sql database alongwith other data like os, browser, referral url then "<script>doc" is saved. Hope you understand.. MI6
Its working in browser because you are echoing the PHP variable, which is sending the javascript code to the browser. The browser is executing the js and you are seeing the output. Look at the source code of the page and you will understand... When you send the PHP var to db, then again its sending the same js code to the db, and it stores that code, instead of the js output. You need ajax to send js output to a PHP variable. Just find a js ajax function, and append height and width to a PHP script in url being called by the ajax. In the php script, GET the appended values and store in a database.
Thanks for explaining this to me, now I understand what's going on with this variable. Actually I already did this by appending variable value in url and then extracting value by GET method and it works fine. But after refresh sometimes "referrer url" is set to same php page. Since after processing data I have to forward visitor to external website so I don't want my php page url is shown as "referral url" in external site statistics. Any idea how to stop php setting "referral url" if screen resolution is get by this method? MI6
The referrer is in "their" server log, I don't think you will be able to control it. However, if you wish to hide just this processing page URL, then first redirect to another URL on your website, which is not so unsafe to reveal, then from that page sent the user to third party website. Also, I don't know how you are referring, cause I think a header("location: third_party_url") will not set current page as referrer page...