Alright I am practicing using cURL to login to different webservices. For this pariticular try, I am doing YouTube. This was a pretty big challenge, but I finally got it…almost.
After posting the HUGE amount of post data tags to the login page, you get sent to a checkCookie kind of thing. The checkcookie page verifies that you have the right cookies and then redirects you to youtube.com (logged into your account) This is whats messing me up.
When I have this:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
I get the source of the checkcookie page. It simply says “Document Moved”. This isn’t what I want, I want to get the source of me being logged in stored into a variable. So I tried something else…
When I use this setup:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
I get sent to the youtube page and I am logged in! It seems to work! Except…I don’t want to be redirected off my script. My goal is to get the source of youtube.com with me logged in.
In other words, the cURL is logging in just fine, the problem is I literally get redirected to YouTube. Which I don’t want.
Any suggestions? It’s like I need to follow the redirects…but not be redirected.
Thanks for any help!
try this: