|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
How to protect a php file from misuse?
I have two files. One is an html page and in it is a call to a php page (I'm using it to generate a dynamic text png).
page_1.html <html> <img scr="heading.php?text=testing"> </html> heading.php <?php php image generation stuff here ?> I want to know if there's a way, using session variables or .htaccess protection or whatever, to allow users to load 'page_1.html' normally but not allow users to access 'heading.php' directly (by putting 'heading.php?text=some super long random text here' into their browsers). My first thought was to have 'heading.php' only run when a certain variable was passed to it from 'page_1.html' but that hasn't worked correctly. Any ideas? |
|
#2
|
||||
|
||||
|
Maybe do a referer check in the PHP file, looking for page_1.html. It's not foolproof, but it'd keep your average user from abusing the file.
__________________
Please don't PM me asking for solutions outside the scope of a thread. Keeping all responses in a thread stands to help others who come along later, which is after all what this forum's all about. |
|
#3
|
|||
|
|||
|
>Maybe do a referer check in the PHP file, looking for page_1.html. It's
>not foolproof, but it'd keep your average user from abusing the file. How would that work if I had 100 HTML pages accessing the script? Could a referer check for and only allow requests coming from a certain directory? |
|
#4
|
||||
|
||||
|
Sure, you could look for a directory or even a domain. A domain would be preferable, in fact, as anyone on to your spoof check could create a directory on their server and get past your check without even having to write any spoof code.
|
|
#5
|
|||
|
|||
|
So, the PHP file would check that the request was coming from:
http://www.domain.com/html/page_1.html and the PHP could sit in http://www.domain.com/php/heading.php Is this correct? If you happen to know what the referer code might like that'd be great. But I will look around and try to figure it out. Thanks. |
|
#6
|
||||
|
||||
|
If you want to just check by domain, try:
PHP Code:
To restrict access to a given page: PHP Code:
Or for a directory: PHP Code:
Note that dots and slashes have to be escaped within the preg_match() string. Other pattern matching functions could be used as well. |
|
#7
|
|||
|
|||
|
Great, thanks so much.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > How to protect a php file from misuse? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|