a2bardeals Posted March 13, 2007 Share Posted March 13, 2007 I am trying to create a PHP page with a variable's value being looked up from google's geocoding service. Basically I have a MySQL database table with customer names and addresses. On the page I am working on I want to do a quick lookup to: http://maps.google.com/maps/geo?q=Address+Info&key=abcdefg&output=csv when you type this in a browser in returns a small line of text that has the lat/long seperated by commas. How can I get that data from the HTTP request into a variable without leaving my site? I know you can use cURL but I cannot install it on my system (no compiler) so I am looking for an alternative... i was thinking i could use fopen() or fsockopen() but I have no idea how to set this up. Any ideas? Link to comment https://forums.phpfreaks.com/topic/42581-can-i-use-fopen/ Share on other sites More sharing options...
per1os Posted March 13, 2007 Share Posted March 13, 2007 $string = file_get_contents($url); --FrosT Link to comment https://forums.phpfreaks.com/topic/42581-can-i-use-fopen/#findComment-206661 Share on other sites More sharing options...
karthikeyan_coder Posted March 13, 2007 Share Posted March 13, 2007 try cUrl(); Link to comment https://forums.phpfreaks.com/topic/42581-can-i-use-fopen/#findComment-206664 Share on other sites More sharing options...
a2bardeals Posted March 14, 2007 Author Share Posted March 14, 2007 ok I love the help... however I have tried both...I cannot install cURL on the system and I'm only running PHP 4.1.2 which does not include the file_get_contents() function....are these the only ways of doing this? Link to comment https://forums.phpfreaks.com/topic/42581-can-i-use-fopen/#findComment-207294 Share on other sites More sharing options...
per1os Posted March 14, 2007 Share Posted March 14, 2007 function file_get_contents2($filename) { $fd = fopen("$filename", "rb"); $content = fread($fd, filesize($filename)); fclose($fd); return $content; } try that --FrosT Link to comment https://forums.phpfreaks.com/topic/42581-can-i-use-fopen/#findComment-207300 Share on other sites More sharing options...
a2bardeals Posted March 14, 2007 Author Share Posted March 14, 2007 returns nothing...am i calling the function right? <? function file_get_contents2($filename) { $fd = fopen("$filename", "rb"); $content = fread($fd, filesize($filename)); fclose($fd); return $content; } $string = file_get_contents2('http://maps.google.com/maps/geo?key=ABQIAAAAR0Cth1uWGX8aUnZOUNxxDRSTa-vPv41zs_3mMYBEENmT6-JqMxQvgmczA_f8sbJvBlQCW7hrjqwVQA&output=cvs&q=3060+Packard+Rd,+Ann+Arbor,+MI'); echo $string; ?> Link to comment https://forums.phpfreaks.com/topic/42581-can-i-use-fopen/#findComment-207352 Share on other sites More sharing options...
per1os Posted March 14, 2007 Share Posted March 14, 2007 Looks right to me, maybe a half-assed solution is trying to include the file? I am not sure if it will work but give it a try ob_start(); include("http://maps.google.com/maps/geo?key=ABQIAAAAR0Cth1uWGX8aUnZOUNxxDRSTa-vPv41zs_3mMYBEENmT6-JqMxQvgmczA_f8sbJvBlQCW7hrjqwVQA&output=cvs&q=3060+Packard+Rd,+Ann+Arbor,+MI"); $string = ob_get_contents(); ob_end_clean(); echo $string; --FrosT Link to comment https://forums.phpfreaks.com/topic/42581-can-i-use-fopen/#findComment-207363 Share on other sites More sharing options...
a2bardeals Posted March 14, 2007 Author Share Posted March 14, 2007 still nothing...im starting to think there is no workaround which is why cURL and file_get_contents were introduced maybe? Link to comment https://forums.phpfreaks.com/topic/42581-can-i-use-fopen/#findComment-207367 Share on other sites More sharing options...
per1os Posted March 14, 2007 Share Posted March 14, 2007 as posted on: http://us2.php.net/manual/en/function.include.php Warning Windows versions of PHP prior to PHP 4.3.0 do not support accessing remote files via this function, even if allow_url_fopen is enabled. allow_url_fopen that is probably disabled via your host, if that is there is really no luck for you unless you can google a allow_url_fopen workaround and find that. --FrosT Link to comment https://forums.phpfreaks.com/topic/42581-can-i-use-fopen/#findComment-207373 Share on other sites More sharing options...
a2bardeals Posted March 14, 2007 Author Share Posted March 14, 2007 ok well i do not have a windows version...I have a Mac OS X version (UNIX version) of PHP 4.1.2 should that matter? Link to comment https://forums.phpfreaks.com/topic/42581-can-i-use-fopen/#findComment-207385 Share on other sites More sharing options...
a2bardeals Posted March 14, 2007 Author Share Posted March 14, 2007 well i have just purchased the new OS X with Xcode for my server which should give me a compiler and allow me to use cURL and I will try that route and updating my PHP version should help as well Link to comment https://forums.phpfreaks.com/topic/42581-can-i-use-fopen/#findComment-207389 Share on other sites More sharing options...
per1os Posted March 14, 2007 Share Posted March 14, 2007 That would explain why the include didn't work and why file_get_contents didn't work http://us2.php.net/manual/en/function.file-get-contents.php (note version information) The file_get_contents2(); would have worked if the fopen works. If the fopen is not allowed to connect to a remote site than I think you are SOL. http://us2.php.net/manual/en/function.fopen.php Maybe look through that at the user comments. Best of luck. --FrosT Link to comment https://forums.phpfreaks.com/topic/42581-can-i-use-fopen/#findComment-207390 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.