dreamwest Posted July 17, 2009 Share Posted July 17, 2009 How can i store document.write as a variable This outputs the country code "AU" <script language="JavaScript">document.write(geoip_country_code());</script> Now i need to use it in a php script <? $code = ;//document.write output here ?> Link to comment https://forums.phpfreaks.com/topic/166312-documentwrite-as-a-variable/ Share on other sites More sharing options...
rhodesa Posted July 17, 2009 Share Posted July 17, 2009 so, since JavaScript is run client side, and PHP is server side, you can't directly use it. You need to send it back to the server, and for that you have a couple of options. 1) Do an AJAX call. If you are going to do this, I would suggest checking out jQuery...it will make your life way easier. Basically, you can submit data in the background. 2) If this is the only value you care about though, it's probably easier to just pass it in a resource call. The resource could be a CSS file, JS file, or an image. For example: <script language="JavaScript"> var img = new Image(); img.src = 'geo_track.php?geo='+geoip_country_code(); </script> The browser will request an image at that url, where you can have a PHP script to process the info, then sends back a 1 pixel blank image or just nothing at all Link to comment https://forums.phpfreaks.com/topic/166312-documentwrite-as-a-variable/#findComment-877010 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.