I am aware that you can use Java to execute the php file from a website like below:
URLConnection conn = new URL("http://localhost/file.php").openConnection();
conn.connect();
However would it be possible to make Java read the php file as a text file and how? (Possibly via the use of the BufferedReader)
Thank you.
If you mean to read the
phpsource, then the answer is no – you cannot readphpsource in a typical webserver configuration. In most cases it would be very insecure to allow it – passwords and other constants are often stored inphpsource code.If however, you are just meaning to read out the result of executing the
phpdocument, as a browser would do, you can use something like;To read the source of a remote
phpdocument via http, the webserver needs to be configured to not parse & execute the file, rather just serve it blindly as a plain text file.This can be achieved in a few ways;
php– no php engine, no code execution..phpsourcewould do the trick in many instances..htaccessyou can alter webserver configurations for a single directory. You would want to do something likephp_flag engine offorRemoveHandler .phpNote that only the first, and maybe the second, method above does not open up potential security holes in your server. So use with caution.