Server can read php

Php web server can not read php files

Question: i want to use this web server in php and in my index.php is echo function to write a string or other functions but this web server can not run that echo or other php functions and in my localhost i see full withe page and this is my problem where is the problem ? A properly configured Apache server will not serve raw PHP files though, it should always process them with the PHP interpreter first.

Php web server can not read php files

i want to use this web server in php

set_time_limit(0); $address = '127.0.0.1'; $port = 80; $sock = socket_create(AF_INET, SOCK_STREAM, 0); socket_bind($sock, $address, $port) or die('Could not bind to address'); echo "\n Listening On port $port For Connection. \n\n"; while(1) < socket_listen($sock); $client = socket_accept($sock); $input = socket_read($client, 1024); $incoming = array(); $incoming = explode("\r\n", $input); $fetchArray = array(); $fetchArray = explode(" ", $incoming[0]); $file = $fetchArray[1]; if($file == "/")< $file = "index.php"; >else < $filearray = array(); $filearray = explode("/", $file); $file = $filearray[1]; >echo $fetchArray[0] . " Request " . $file . "\n"; $output = ""; $Header = "HTTP/1.1 200 OK \r\n" . "Date: Fri, 31 Dec 1999 23:59:59 GMT \r\n" . "Content-Type: text/html \r\n\r\n"; $Content = file_get_contents($file); $output = $Header . $Content; socket_write($client,$output,strlen($output)); socket_close($client);

and in my index.php is echo function to write a string or other functions but this web server can not run that echo or other php functions and in my localhost i see full withe page and this is my problem where is the problem ?

There can be several reasons for this error (one of which for example that your web server has not read permissions and thus cannot open the . PHP files ). You could try enabling the php logs and setting your preffered locations and read the error that prevents your code from being displayed.

PHP security : retrieving PHP file from server, un, If you are talking about someone else’s server, then the short answer is no. If third parties could read your PHP source code, that would be quite a security hole, since PHP files tend to contain database passwords, hash keys, proprietary algorithms and other goodies that you don’t want falling in the wrong hands. Usage examplephp_value engine offFeedback

PHP Read files inside of the server root

In my current PHP script I am attempting to read files which are not inside of /var/www/html (which the script seems to be limited too) but files inside of /root/ or anywhere behind /var/www/html .

Читайте также:  Python asyncio open file

Just to explain why, I need to read critical data from files which I do not want downloadable or accessible under any circumstances (no matter how much verification).

I have messed around with getcwd() and chdir($_SERVER[‘DOCUMENT_ROOT’]) but with no success.

My question: Is this even possible, and if so, how can I do this?

P.S. My method of reading is just standard fopen($filename, «rb») and fread ;

It depends if php has the permissions to access the required files. You’ll need to allow permissions for the user «www-data» (if you’re using apache on linux) to be able to read the files.

Php web server can not read php files, and in my index.php is echo function to write a string or other functions but this web server can not run that echo or other php functions and in my localhost i see full withe page and this is my problem where is the problem ?

PHP- How to read files from FTP in PHP?

I have 2 files. One is email.php and link.html. I have used anchor tag

in link.html and want to read report_ledger.html which is located on FTP server . I can connect with FTP server but I am getting following error :

Connected as ftpkalpesh@ftp.firstnorthglobal.com Warning: file_get_contents(ftp.firstnorthglobal.com/report_ledger.html) [function.file-get-contents]: failed to open stream: No such file or directory

Fatal error: Uncaught exception ‘Swift_IoException’ with message ‘Unable to open file for reading [ftp.firstnorthglobal.com/shreelogo.png]’ in C:\xampp\Swift-5.0.3\lib\classes\Swift\ByteStream\FileByteStream.php:139 Stack trace: #0 C:\xampp\Swift-5.0.3\lib\classes\Swift\ByteStream\FileByteStream.php(86): Swift_ByteStream_FileByteStream->_getReadHandle() #1 C:\xampp\Swift-5.0.3\lib\classes\Swift\Mime\ContentEncoder\Base64ContentEncoder.php(36): Swift_ByteStream_FileByteStream->read(8190) #2 C:\xampp\Swift-5.0.3\lib\classes\Swift\Mime\SimpleMimeEntity.php(557): Swift_Mime_ContentEncoder_Base64ContentEncoder->encodeByteStream(Object(Swift_ByteStream_FileByteStream), Object(Swift_Transport_StreamBuffer), 0, 78) #3 C:\xampp\Swift-5.0.3\lib\classes\Swift\Mime\SimpleMimeEntity.php(532): Swift_Mime_SimpleMimeEntity->_bodyToByteStream(Object(Swift_Transport_StreamBuffer)) #4 C:\xampp\Swift-5.0.3\lib\classes\Swift\Mime\SimpleMimeEntity.php(572): Swift_Mime_SimpleMimeEntity->toByteStream(Object(Swift_Transport_StreamBuffer)) #5 C:\x in C:\xampp\Swift-5.0.3\lib\classes\Swift\ByteStream\FileByteStream.php on line 139

I did not use any file reading function. What would you suggest?

I think that you use this function as you want to open a local file and not a remote one.

Look at docs here: file_get_contents

When i talk about URL and try to enable: fopen wrappers

Personal idea( this example is to upload but if you use ftp_get instead of ftp_put you can find the solution ):

 else < echo "There was a problem\n"; >// close the connection ftp_close($conn_id); ?> 

Use php to read the source of a php file, You have to configure your server not to run php at requests to/from localhost. When you perform a HTTP request (and not the direct request to the file system) the server should run php script, it is a purpose of the server. – Cheery Mar 1, 2012 at 0:25 1 @MarkBrown Then you’re still reading the file via the …

Can a PHP file ever be read externally?

Is it possible for someone to ‘hack’ an apache server and read PHP files . I understand that PHP is a server-side language and cannot be read from anywhere other than the server, but could someone hack the server and read them as if reading a text file?

Читайте также:  Css colors code red

Well yes, if they ever actually hack into the server (SSH, FTP etc.), they may have access to files on the hard disk. A properly configured Apache server will not serve raw php files though, it should always process them with the PHP interpreter first.

To avoid problems with misconfigured Apache servers though (even just temporary glitches), it’s advisable to keep the application files outside the public webroot. Put only a small bootstrap PHP file into the webroot which may be exposed in a pinch, but which just includes other PHP files which are not publicly accessible.

There are several options for someone to be able to read the PHP source files on a server.

  1. Think about a misconfiguration of the server
  2. A hack of the server
  3. Not opening the PHP file with
  4. Temporary / backup files (Think index.php~ or index.php.bak )
  5. etc.

I understand that PHP is a server-side language and cannot be read from anywhere other than the server

That only means the files are processed on the server side. It doesn’t mean the source is bound to the server in some way.

NASA can be hacked. The FBI can be hacked. Your shared server can definitely be hacked.

Yes, of course they could — if the server is penetrated then any file on it is visible.

Read file on the server using PHP, I am working on PHP. I want to read a file from a server. For example. And i wan to display all the files content on PHP page, The problem is how to Stack Overflow. About; Products For Teams; Stack Overflow Public questions & answers; Stack

Источник

PHP — Read file from remote server

So I have two CentOS servers. On server1 I have a log in the directory /home/something/logs/latest.log On server2 I have my apache server, and I want it to read the log on server1. I need to do this because I want to make a real time console, displaying data from the log on server1 I will get the data from the log in one PHP file and then do some ajax in another file and then I have a real time log. My questions: How can I read a file from a remote server with php? Does anybody know a better solution?

1 Answer 1

A quick visit to the PHP docs will tell you that it’s incredibly easy to do 🙂

But in summary, all you need to do is:

$myfile = file_get_contents("http://server1/blah/blah/file.log"); 

Note: though. for this to work, you will need that file to be accessible, via a web server running on server1, since it’s a static file, then installing something like NginX and just placing the doc in the default root (or pointing the default root at the home folder) will be enough to allow you to use the PHP get file contents call.

If, putting a web server on server1 is NOT an option, then essentially your going to have to follow these steps.

  • Connect to server1 using something like SSH/Telnet, or one of the remote copy utils, or set up an FTP server and point it to your home folder.
  • Use one of PHP’s many connection methods (Which one, depends on the service you chhose above)
  • Then create a script that, connects using the selected connection method in step 2, automates any parameters needed, and connects.
  • Once connected, issue any commands needed (Depending on the connection method used) to grab the file and it’s contents.
  • Disconnect from the server and process the file.

With SSH, you’ll need to use the SSH2 functions built into PHP (Again, the doc’s are on php.net), there’s a class documented there you can use.

For Telnet, similar difference, but A) I wouldn’t recommend it and B) you’d need to do a lot of code to support the telnet protocol over raw sockets.

For FTP, well PHP has (and has for a long time) had FTP support baked in, but as with a web server, you’ll need to install and set up FTP, then secure it and all that jazz, if your going to do this, then it’s easier to get it working with a web server.

Beyond that, well you could adopt the *nix philosophy of many small tools, and use exec and system calls to run programs from your Linux distro, such as ‘rcopy’, ‘sftp’ and many others, but again that’s quite a task, to know what to automate, where and how.

You also have the option of writing your own ad-hoc server, that listens on a socket, and sends the log when a connection is made.

Lastly, you could feasibly also share a folder using NFS or Samba, then just use normal file open/read/close calls as though the file was local, but then you’ve got to set up users, shares, auth and a load of other things.

Which route you go, depends on how much work your willing to do, and what restrictions you do/don’t have preventing you from using any of the methods outlined here.

My advice though, go the web server method, use NginX, minimal config, seal the log file server away behind closed doors and let php do what it’s good at, and grab the file over http.

Источник

Оцените статью