KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to make curl follow a redirect but I can't quite get it to work right. I have a string that I want to send as a GET param to a server and get the resulting URL. Example: String = Kobold Vermin Url = www.wowhead.com/search?q=Kobold+Worker If you go to that url it will redirect you to "www.wowhead.com/npc=257". I want curl to return this URL to my PHP code so that i can extract the "npc=257" and use it. Current code: function npcID($name) { $urltopost = "http://www.wowhead.com/search?q=" . $name; $ch = curl_init(); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"); curl_setopt($ch, CURLOPT_URL, $urltopost); curl_setopt($ch, CURLOPT_REFERER, "http://www.wowhead.com"); curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:application/x-www-form-urlencoded")); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); return curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); } This however returns www.wowhead.com/search?q=Kobold+Worker and not www.wowhead.com/npc=257 . I suspect PHP is returning before the external redirect happens. How can I fix this?
Tags (comma-separated)
Save Edits
Cancel