The online racing simulator
How to show the content of a .txt file in a website?
Well ,as said in the subject of this thread.

I would like to have the content of one of my .txt files (Live-Updated) Hosted on my dedicated server

How do i do this? Any ideas?

Thanks in advance
#2 - PoVo

<?php 
php

include('blah.txt');


?>

And if it's located in a directory? Like C:\LFS\BLABLA.TXT?
#4 - PoVo
Write the whole path.


<?php 
include('C:\Files\More_Files\Derp.txt');
?>

This will only work if the web server is located on the same server as the file, and as long as the web server has permissions to access the file.
Sorted,

Many thanks PoVo
Just so anyone doesn't read this in the future and have an incorrect answer, you shouldn't ever use include in the way that POVO suggested. If you wanted to echo out content you're better off using something like file_get_contents.

Include like POVO suggested is more for when you're needing to include PHP source files, not general content.
It's a possible security risk.
Quote from dawesdust_12 :Just so anyone doesn't read this in the future and have an incorrect answer, you shouldn't ever use include in the way that POVO suggested. If you wanted to echo out content you're better off using something like file_get_contents.

Include like POVO suggested is more for when you're needing to include PHP source files, not general content.

Oh :/

Which is the good final code then??
Quote from Chriship :Oh :/

How is the good final code then??

I guess it could look like this:


<?php 
$output 
file_get_contents('C:\Files\More_Files\Derp.txt');
echo 
$output;
?>

You can just echo file_get_contents(), there is no need for the variable.
#11 - PoVo
Sure it's a security risk if there's a possible way of getting PHP code included in the file.

Considering the text file he is trying to output is an Airio statistics file, that shouldn't really matter. Nobody else but the end user (customer) has access to this file and I really doubt they would write anything malicious into the file when it's being used for their own website.
Except doing an include like that isn't correct. If you know you're dealing with string content (that isn't PHP), why not do the correct thing and do "echo file_get_contents('file.txt');" Using include to get stuff to the output buffer in that way is dirty.
Quote from PoVo :Nobody else but the end user (customer) has access to this file and I really doubt they would write anything malicious into the file when it's being used for their own website.

That's the point tho. Just because it's supposed to only be used by the program it's still an attack vector for someone to use if the file was writable on the server it could become an attack surface for something else. Whereas file_get_contents would be a much more appropriate use as it does not introduce this attack vector.
Quote from Dygear :You can just echo file_get_contents(), there is no need for the variable.

Yes, true
********

Edit: Works perfectly now with file_get_content

The( "header('Content-type: text/plain');" was missing in flame's code

Thanks , sorted now , with file_get_content (y)
Quote from Dygear :That's the point tho. Just because it's supposed to only be used by the program it's still an attack vector for someone to use if the file was writable on the server it could become an attack surface for something else. Whereas file_get_contents would be a much more appropriate use as it does not introduce this attack vector.

Further to Dygears point, you should always try to code defensively. Just because your use case doesn't appear to have any vulnerabilities or you think it's safe... Why not attempt to make it more safe by using the most secure (while feasible) solution.
Quote from dawesdust_12 :Further to Dygears point, you should always try to code defensively. Just because your use case doesn't appear to have any vulnerabilities or you think it's safe... Why not attempt to make it more safe by using the most secure (while feasible) solution.

Indeed, Thanks for the help , appreciate it a lot

FGED GREDG RDFGDR GSFDG