Here is code I wrote awhile back that acts like a web browser. It's written as a PHP class. I haven't worked on this class for along time so there are no guarantees. But it should give you a good example of how you can do things.
I'm not going to write the code for you, so I'd suggest you read through this and see what it's doing. Trust me doing it yourself is a much better learning technique than having someone just show you how it's done.
What this class was written for was an experiment in building an anonymous browser. It would take in a URL and open that page inside the current browser. The user would be linking to 1 site but the site shown in the browser would be another site. I was able to successfully surf yahoo.com with this code. There is alot of stuff that you probably won't care about, but the code for opening the socket, building the header, and retrieving the page are all functional pieces.