Here is what you can do.
When you open up the socket with URL1, there will be some kind of an instruction that your browser will understand, which will make it redirect the page to whatever link is provided. PHP will not do anything when you read the page because it's not a browser and will read the instructions as pure text. When you extract the text from URL1 you'll find some JavaScript in there with URL2 hard-coded in it. Grab that URL and store it in $string variable and open up a new socket using that string as the link. You can close the connection with URL1 at this point and keep the connection with URL2.
I hope this works. If you have any trouble or if you need better explanation, reply back with the contents of URL1 and I'll tell you how to do it.
Rubric