Hey there, nice to meet you.
This is a difficult job to do in PHP, so I'd like to suggest an alternative, if you don't mind.
In Python, there is a very useful library called Requests, and it is much easier to use for login sessions than PHP's CURL. In addition, it will be much easier to access the MySQL database because of a library called SQLAlchemy.
Let me know what you think of my proposal, and message me if you need any more details.
Thanks for the opportunity, I hope you have a nice day!
-- Daniel Newhard