newbtophp Posted August 13, 2009 Share Posted August 13, 2009 I was wondering is their a way i can make the text.txt file execute when using fopen, but when i visit the file directorally it will display a forbidden message? I've tried chmodding, the forbidden message displays but fopen wont work This is my code: //I want the url to be forbidden, so vistors can't access directaly $url="http://domain.com/text.txt"; //But the trouble is if i chmod the above file the below code wont work $fp = fopen($url, "r"); All help is apreciated Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted August 13, 2009 Share Posted August 13, 2009 Erm, dunno much bout this but either Use .htaccess, try googling? Or Make it password protected and use curl to access it? Just throwing ideas out Quote Link to comment Share on other sites More sharing options...
yjim Posted August 13, 2009 Share Posted August 13, 2009 apache directives / .htaccess would probably be ur best bet. <Files test.txt> Deny from all </Files> Quote Link to comment Share on other sites More sharing options...
newbtophp Posted August 13, 2009 Author Share Posted August 13, 2009 So I create a .htaccess file in the root. Containing the following code: <Files test.txt> Deny from all </Files> What if I wanted to protect a whole folder's content?, do i just replace the file name with the folder path? Quote Link to comment Share on other sites More sharing options...
yjim Posted August 13, 2009 Share Posted August 13, 2009 <Directory /test> Deny from all </Directory> Quote Link to comment Share on other sites More sharing options...
newbtophp Posted August 14, 2009 Author Share Posted August 14, 2009 Tested, it makes the folder and protected files forbidden but fopen wont work. Warning: fopen(http://domain.com/text.txt) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /home/me/public_html/test.php on line 9 Any other way? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 14, 2009 Share Posted August 14, 2009 Use a file system path to open the file with. When you use a URL, you are causing your web server/php to make a http request back to itself, just like a browser would, to read the file. Using a URL also takes about 100 times longer to read the file than if you were reading it through the file system. Quote Link to comment Share on other sites More sharing options...
newbtophp Posted August 14, 2009 Author Share Posted August 14, 2009 the txt is located externally on another site, so file path wouldnt work Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.