Page 1 of 1

please help

Posted: Sun Mar 21, 2010 1:30 am
by tomindo
HI guys
I am trying to fully understand the line in blue, can someone give me a detailed translation of this line. What "index%3Dbooks" means ?
thanks a lot

Code: Select all

<?php
// FIND BOOKS ON PHP AND MYSQL ON AMAZON
$url = "http://www.amazon.com/exec/obidos/search-handle-form/002-5640957-2809605";
$ch = curl_init();    // initialize curl handle
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 3); // times out after 4s
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
[color=#0000FF]curl_setopt($ch, CURLOPT_POSTFIELDS, "url=index%3Dbooks&field-keywords=PHP+MYSQL");[/color] // add POST fields
$result = curl_exec($ch); // run the whole process
curl_close($ch); 
echo $result;
?>

Re: please help

Posted: Sun Mar 21, 2010 3:26 am
by cpetercarter
The string needs to be url encoded. "%3D" is the url encoding of "=", so "index%3Dbooks" means "index=books".

Re: please help

Posted: Sun Mar 21, 2010 12:16 pm
by tomindo
cpetercarter wrote:The string needs to be url encoded. "%3D" is the url encoding of "=", so "index%3Dbooks" means "index=books".
sound like silly question but why does it have "index" in here? I have put the code in dreamweaver and navigate to that field but in the property , I don't see any where that defines "index" except the "field-keywords"?
thanks

Re: please help

Posted: Sun Mar 21, 2010 12:44 pm
by cpetercarter
I don't know. But if you put http://www.amazon.com/exec/obidos/searc ... =PHP+MYSQL into the address bar of your browser, you get an Amazon search for books about php and mysql.

Re: please help

Posted: Sun Mar 21, 2010 1:40 pm
by tomindo
cpetercarter wrote:I don't know. But if you put http://www.amazon.com/exec/obidos/searc ... =PHP+MYSQL into the address bar of your browser, you get an Amazon search for books about php and mysql.
that is right. I want to understand how they came up with that line, where they got the variables and values. The other variables make sense to me except the "index" one. I just can't find in anywhere in amazon source code as well as the dream weaver interface.

Someone can shed a light on this , that would be great
thanks

Re: please help

Posted: Sun Mar 21, 2010 4:32 pm
by cpetercarter
I don't know how much more I can help. But remember that the url query string consists of a number of name - value pairs. In this case the name is "url" and the value is "index%3Dbooks" or "index=books". Does this help?

Re: please help

Posted: Sun Mar 21, 2010 5:22 pm
by tomindo
cpetercarter wrote:I don't know how much more I can help. But remember that the url query string consists of a number of name - value pairs. In this case the name is "url" and the value is "index%3Dbooks" or "index=books". Does this help?
it does not make sense "value" should only be "books" , there must be something to do with the "index" . Maybe , it is used for drop down menu Im not sure