PHP header can only be called once
I hate spending too much time just trying to solve one little problem. This was seriously one of those times.
To give some background on what I was trying to do, I needed to have a user log into one system and have it automatically authenticate against another site on the same server. Your usual "single sign-on" functionality. The problem was, I didn't want to duplicate a lot of code to encode session data as this app was doing. Instead, I made a request to the login form from the server, passing in the credentials and grabbing the response. Then, I'd pass the Set-Cookie headers back to the client. Voila! Okay, not quite.
First, it turns out that you can't use
header more than once for the same header. It's even documented. Fine, I missed that. Then I needed to break down each of the Set-Cookie headers and recreate them as PHP
setcookie calls. Lastly, it didn't like that I wasn't setting a path. That meant I was getting the Set-Cookie in the response but it wasn't sticking. That had me banging my head, for sure.
Sometimes you can get spoiled using a framework that handles all of this for you. I was tracing HTTP calls, writing out variables, and checking the database trying to figure out why I had different information in all three places.
Thankfully, it all worked out in the end and now I can move to the next problem.