requesting url parameters from a website

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
FREESTYLER
Forum Newbie
Posts: 17
Joined: Tue Oct 18, 2005 10:33 am

requesting url parameters from a website

Post by FREESTYLER »

Hey guys once again im stuck
heres my problem:
i need to send a suburb, address, state, postcode to the url http://www.multimap.com.au/map/places.cgi
this in turn returns a latitude and a longitude
i then need to store these in my php page

i found this code, but dont think its helping.

Code: Select all

$url="http://anything";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "fieldname=fieldvalue&fieldname=fieldvalue&");
#curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec ($ch);
$content = curl_exec ($ch); # This returns HTML
curl_close ($ch);
TO GET A PAGE USING A URL ONLY:

Code: Select all

$url="http://anything";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec ($ch);
$xml = curl_exec ($ch);
curl_close ($ch);
any ideas?
i have this code in java, but its a bit complex to trasnlate into php i think
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

calling curl_exec() with the same curl handle twice simply repeats the operation.. I don't see a need to do so..

The first one is the way to go if the cgi file must be posted to.. otherwise the second will work fine, along with using file_get_contents() if your server allows urls via fopen() based functions..
FREESTYLER
Forum Newbie
Posts: 17
Joined: Tue Oct 18, 2005 10:33 am

Post by FREESTYLER »

ok i dont understand that?
ive read the php doc's on file_get_contents()
seems to want to open a file though?
im new to php sorry
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$content = file_get_contents('http://google.com');
the proceeding code will fetch what google returns from that particular url. It'll be the raw HTML or rather HTTP response, no headers or special information, just the page content. (That is, if your server has allow_url_fopen on)
FREESTYLER
Forum Newbie
Posts: 17
Joined: Tue Oct 18, 2005 10:33 am

Post by FREESTYLER »

ok, ive kinda got it working now
but it returns the html code/ the webpage
i just want to extract to values from the page?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what values? your code above simply requests the page response..
Post Reply