PHP-Auth
PHP-Auth copied to clipboard
Check for cli environment
Hi,
first of all thank your for this great package!
As I am using your package for creating users with some cli scripts I always got the "Headers already sent" error as soon as I echoed out some informations inside my cli script.
So I added a quick environment check by checking for the current SAPI_NAME. Maybe this will help some other users as well.
Best Regards,
CewlBird
Thanks!
Not sure if this solution is really the solution we need.
For example, you could simply change the structure of your application code and change the sequence of calls, and the problem should disappear. That’s because you’d have the same problem on the web: You simply have create the instance before sending your output. Or use output buffering.
Wouldn’t you agree?
Hi, sorry for the late reply.
I understand what you mean, but I don't know if this will work in all cases, as I have some cli outputs before I have created the instance, like prompts or some other stuff that gets written to the console.
I tried output buffering before but it didn't work as expected.
At least in my case changing the sequence of calls is not a solution, as the current app order works properly in the web but my cli scripts will always output some stuff before this class instantiated.
So this was my way to solve this use case.
I shared this snippet just in case anyone had the same use cases like me, so feel free to close this pull request or to merge it someday in the future if some other people need this kind of solution.
Best Regards,
CewlBird