How do I get the actual text content of a .php file using javascript without executing it on the server?
Also, I would like to know if there is a way to read the text content of any other file other than .php using javascript.
If you are using a webserver like Apache or Nginx then they will execute the .php file for you. There is no way around this because you shouldn't allow anyone to download your php source code, which is what you're trying to do with Javascript.
If your javascript needs some output then have your .php render the data javascript needs. Then to load this content via Javascript can be as simple as an ajax call, eg: http://api.jquery.com/jquery.ajax/
php file that echo's your site's source code, then please note: people can visit this file directly and view the contents. They might tamper with $_GET variables. Do not allow this page display things like database passwords or other secret information.I realize this is a very very old question. But it has a very simple solution, without re-configuring the php server, assuming,
Say the file of interest is x.php, make a symbolic link, with a text file extension
ln -s x.php newname.txt
Now you can view the file at the same site as newname.txt.
Minimizing security risk. If your server is already configured to not allow directory browsing, then by making the newname somewhat long, it is less likely anybody else will easily find the name to view it.
*.exeor*.arglebargle. as long as the webserver's been told how to treat that extension, it'll just "work", even though neither of those extensions are "traditionally" served up..phpfiles, because I still need to execute the same file on some other instances.whatever.txt? Since you want it served up as text, then name it as a text file.