Я пытаюсь сделать завиток после перенаправления, но я не могу заставить его работать правильно. У меня есть строка, которую я хочу отправить как параметр GET на сервер и получить результирующий URL.
Пример:
Строка = Вершина Кобольдов
Url = www.wowhead.com/search?q=Kobold+Worker
Если вы перейдете к этому URL-адресу, он перенаправит вас на "www.wowhead.com/npc=257". Я хочу, чтобы curl вернул этот URL-адрес моему PHP-коду, чтобы я мог извлечь "npc = 257" и использовать его.
Текущий код:
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);
}
Это, однако, возвращает www.wowhead.com/search?q=Kobold+Worker, а не www.wowhead.com/npc=257.
Я подозреваю, что PHP возвращается до того, как произойдет внешнее перенаправление. Как я могу это исправить?