/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] How to allow a php script to access a txt file but now allow direct browser access

Hi guys,

I hope this is not a hard question.
I have a text file which contains various information which I want to be able to access from a php script but keep people from being able to browse directly to the text file (and thus see it’s contents).

I have used CHMOD to set the PUBLIC group access to xx0 but this causes the php script to also fail. The php script is run after the visitor enters some information into a input field and presses a button.

I am using sessions, so is it possible to temporarily access the file while the php script is running and turn it off on completion? (Bearing in mind that multiple users might be online at the same time.)

Cheers,
Nap

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@HuevoosMar 12.2008 — You should upload that file outside the public folder, (public_html or www) that way no one can view it from the web and your php files can still find it
Copy linkTweet thisAlerts:
@NapauthorMar 12.2008 — Heuvoos,

Thanks for that.

I have tried it, but how do I structure my fopen statement to read the parent of public_html?

With the file in public_html, I am using the line below to access it.
[code=php]$fp = fopen("datafile.txt", 'r');[/code]

What is the syntax to access the parent of public_html? ( ..datafile.txt )?

Cheers,

Nap
Copy linkTweet thisAlerts:
@NapauthorMar 12.2008 — Heuvoos,

Sorry for the silly 2nd question. I figured it out. Should have been '/' to start with (linux server). I used an absolute path prefix.

Cheers,

Nap
Copy linkTweet thisAlerts:
@HuevoosMar 12.2008 — no problemo ?
×

Success!

Help @Nap spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...