Sounds like your PHP code isn’t following redirects, isn’t a matter of using HTTPS directly instead of HTTP?