Jump to content

PHP curl and GET


nitrus

Recommended Posts

I am trying to add a request header that is generated when a user searches an airport code in the form using weather.com. I have successfully curled the first page, but i am not sure how to implement the next step on using the GET form data.

 

The query string is search?where=phx&start_with=1&search_loc_type=9&x=5&y=13. The phx is the airport code.  This changes everytime someone searches a different airport code

 

I am trying to figure out how to add this query string, for example, search?where="Airport_variable".&start_with=1&search_loc_type=9&x=5&y=13.

So when a person types a airport code its fetched by the weather.com server and added to the search query and displaying the search results based on that query.  What is confusing me is GET request using curl.   The current code will parse the airport weather page, but i can't figure out how to add the missing object.

Can someone please help me?

 

Here is what I have so far:

<?php
$URL = "http://www.weather.com/activities/travel/businesstraveler/";
$chwnd = curl_init();
curl_setopt($chwnd, CURLOPT_URL,$URL);
curl_setopt($chwnd, CURLOPT_VERBOSE, 1);
curl_setopt($chwnd, CURLOPT_POST, 1);
curl_setopt($chwnd, CURLOPT_POSTFIELDS, TRUE);
$returned = curl_exec($chwnd);
curl_close ($chwnd);
// /search?where=bhm&start_with=1&search_loc_type=9&x=0&y=0
?>

I am not sure what to do next so i can make a variable that stores that changing airport code on the end of the query string.

If i use the search box here is teh following query string http://www.weather.com/outlook/travel/businesstraveler/search?where=phx&start_with=1&search_loc_type=9&x=0&y=0

If i use the drop down its this: http://www.weather.com/outlook/travel/businesstraveler/airportprofile/ANC  Where the "ANC" changes.

 

My over all outcome is to display the weather after the drop down or search is request by the get form data. 

Link to comment
Share on other sites

Why are you setting POST options if you are using get? GET variables are passed through the URL, so you can just append them like you would see it in the browser:

$URL = "http://www.weather.com/activities/travel/businesstraveler/search?where=phx&start_with=1&search_loc_type=9&x=5&y=13";

If there are no special headers or anything, you might as well use file_get_contents() or fopen().

Edited by lemmin
Link to comment
Share on other sites

I wasn't exactly sure how to use GET with curl that is probably why I'm using the post field value in curl.  If i just append them like you stated it wont be dynamically changing after the user searches the next airport code right? It will only display that one airport in the phx code.  How would i change this code, so it will dynamically change by which airport code is typed in or selected in the drop down?

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.