Hi - i'm trying to connect to the pizza hut postcode validator using CURL but it doesn't seem to be working. I have a feeling it has something to do with the headers. Any ideas?
$url = "http://delivery.pizzahut.co.uk/?userpostcode=CM145PP&x=12&y=17";
$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Connection: keep-alive", "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3"));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
$result = curl_exec($ch);
I get the result:
Guaranteed red hot to your door - We're experiencing problems with our site so please come back soon.
That URL performs a redirect (302), and when it does so create/updates the ASP.net cookie referencing the previously supplied postcode. You need to store the cookie so the subsequent request knows what postcode you searched for.
A quick search on "curl php cookies" should bear fruit.
Hi - so I added the following line to the request, but still getting the same issue. Is there something else I need to do?
curl_setopt($ch, CURLOPT_COOKIE, "ASP.NET_SessionId=k3zmplax2v1qtc45erxtl5hu; .ASPXAUTH=106B54F85A427924C6930E9F8CF4ECD969F93FAD5FB7A2261B57A03CC541605BCF494C9A61360D360DF7020225F7FA7A944A0E929C4C5519038AAE7487C76EBFC43786D07679E36879CD393A9E4ADFF401B435166ED23A21D5E15FF69A10F3B3CEDBBFB57B26092A8DF696661D44F217C03D32522992E1902EC0AA120E4CD8C87726AF1E11C04F09B69AB2FEE3BB03DD81E3019A; .ASPXANONYMOUS=XPr4-kr8zQEkAAAAZTUyN2Q3YjQtMWJiMC00Y2FjLWI3MGYtYWRiNzlhNjgwMTg0khVyHHjz7kAHmpbD3shVHRYiNcQ1; __utma=193058988.2050382701.1353136223.1353136223.1353262732.2; __utmb=193058918.104.22.1683262732; __utmc=193058988; __utmz=193058988.1353136223.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)");
I am pretty sure you are doing it wrong. I don't think you should be hard-coding the cookie value to your script. Instead you need to set a path to a file that will store your cookies. CURL will then be able to reuse the previously set cookie, just like the real browser does.
What you need is an option CURLOPT_COOKIEFILE
This topic is now closed. New replies are no longer allowed.