I fetched the http://gmail.com source code from browser and by file_get_contents, both are different.
How can i get same source code which is showing in browser, using php or js or any other programming language (But i preffer php or js)
Join Stack Overflow to learn, share knowledge, and build your career.
I fetched the http://gmail.com source code from browser and by file_get_contents, both are different.
How can i get same source code which is showing in browser, using php or js or any other programming language (But i preffer php or js)
gmail.com almost certainly does User Agent sniffing to alter the output according to the browser making the request (despite it being considered bad practice and despite google penalising others for doing it). So my guess is that you're unlikely to get the same source code even between two different browsers, let alone if you fetch it with file_get_contents
.
You might get somewhere if you use the cURL library instead, and spoof the UA string, but I wouldn't count on even that working completely.
But even if you do that and it works, gmail.com as a site is really heavily dependent on dynamically loaded content; even parts of the script are only loaded when required. I can't see any possible way that loading the gmail site into a PHP script could be remotely useful. And even if you do get it loaded as you want to, what then? They're constantly changing the code, so trying to write a program to parse the HTML code will be an exercise in futility and frustration.
I guess the real question is what are you trying to achieve here? If you want to load your mail from gmail, they provide proper APIs for that kind of thing, which will work much better and more reliably than trying to parse the gmail site itself. I can't think of many other reasons you'd want to do this, so perhaps you should look into the APIs.
The Gmail API for PHP can be downloaded here: http://code.google.com/p/gmail-api/downloads/detail?name=gmail-api.v0.1.php
Browser shows the generated source code of google.com
and the php only gets the text written in that index file of google which is Javascript ofcourse!