简体   繁体   中英

php curl to page and store $_GET variable in a cookie before page redirects

I am using php curl to view this webpage remotely http://agentnet.propertyguru.com.sg/ex_login?w=1&redirect=/ex_home

The page redirects to another page /distil_identify_cookie.html?uid=... before redirecting back to the initial login page

I have set the following in my curl script

curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, FALSE);

This did not stop the page from redirecting.

Can anyone advise how I can store this $_GET variable "uid" in a cookie before the page redirects?

Add:

After executing the curl statements ($response = curl_exec($ch);), $response is as per below

HTTP/1.1 200 OK Server: nginx Date: Sun, 06 Jul 2014 08:47:32 GMT Content-Type: text/html 
Transfer-Encoding: chunked Connection: keep-alive Vary: Accept-Encoding 
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 
Expires: Thu, 19 Nov 1981 08:52:00 GMT Pragma: no-cache 
Set-Cookie: PHPSESSID2=94l8r0sainetrrc3vl0r7dl2f4; path=/; domain=.propertyguru.com.sg     
Set-Cookie: __PAGE_REFERRER=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=agentnet.propertyguru.com.sg 
Set-Cookie: __PAGE_SITE_REFERRER=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; domain=agentnet.propertyguru.com.sg 
Vary: Accept-Encoding X-Distil-CS: MISS

I cannot find anything in the header stating the uid value...

You can set both CURLOPT_FOLLOWLOCATION and CURLOPT_HEADER to TRUE. This way, in the final result you`ll have the headers for all redirects that happen during your request. Then, you can parse the headers to get the info you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM