HTTP Location Redirect Information with PHP’s Curl Extension for development

If you have to deal with HTTP Location headers or HTTP Cookies then being able to see full header output is important.

Seeing every single redirect is very simple using Curl.  Being able to see each cookie header can also be important.  For example, what if your code is deleting and then setting a cookie several times just prior to sending the headers?  Reviewing the HTTP headers can assist you in improving your code and minimizing HTTP redirects.  Using curl can also provide you with redirect time and other useful page information by using the curl_getinfo function.

An example PHP script that can print out useful information about the HTTP header Location and HTTP cookies can be found here.

Example output is below (May be outdated, check the GIT Readme):

(Please see http_headers.txt output for a full list of headers from all requests during redirection.)

Initial URL: http://gmail.com
Effective URL: https://accounts.google.com/ServiceLogin?service=mail&passive=true&continue=https://mail.google.com/mail/?ui%3Dmobile%26zyp%3Dl&scc=1&ltmpl=ecobx&nui=5&btmpl=mobile&emr=1
Redirect Count: 2
Redirect Time: 0.193121
Locations:
https://mail.google.com/mail/
https://accounts.google.com/ServiceLogin?service=mail&passive=true&continue=https://mail.google.com/mail/?ui%3Dmobile%26zyp%3Dl&scc=1&ltmpl=ecobx&nui=5&btmpl=mobile&emr=1
HTTP Cookie Data:
# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.

#HttpOnly_accounts.google.com FALSE / TRUE 1478826642 GAPS 1:agP-Dwh5TjL_-TCR_TyE1V8tmTlyyA:_AKh5RagJyJV-Rrj
accounts.google.com FALSE / TRUE 0 GALX H6aIpryb0s8