Jump to content

can i use fopen?


a2bardeals

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.