English 中文(简体)
Security in PHP
原标题:

I ve written some PHP scripts to do some server-side work on a headless linux server machine on a LAN. For example, I have http://ipadress/php/operations.php?operation=registerUser&uName=X&uAlias=Y. Now, I want to secure my operations script so that; not everyone on LAN can call it and/or run it but; only the ones that ... have a pre-shared key...? This is the point I m stuck at, requiring a pre-shared key through a GET/POST parameter would be easisest and probably the worst solution. What is/are a more secure way(s) of achieving client-limitation on php scripts?

(I m thinking of maybe requiring a crypted key file from client when starting the session, and denying access to everybody who havent started a scure session...? That s just me theoratically thinking, have no idea where to start to do it in php.)

edit: I clealrly remember writing "requiring a pre-shared key through a GET/POST parameter would be easisest and probably the worst solution." at my original post, so please kindly stop answering with this same thing over and over again.

edit2: to clear things up: the operations.php is called by a program on client machines on same LAN. I dont want any non-client or stranger machine to use operations.php and dont want anyone to be able to access it through browser. I require some kind of security/authentication method to prevent that. I m not looking for login forms or simple HttpAuths... Also, I cant just simply put limitations over IP adresses because; it s just not practical and kinda worse than hard coded non crypted passwords...

最佳回答

If you re using Apache with mod_ssl, it can force clients to authenticate using certificates that are signed by a specific certificate authority.

In theory, you could create just three certificates: Your signing certificate, your server s certificate, and one certificate to distribute to the clients.

This is generally considered a bad idea, though. It s usually better to distribute a separate certificate to each client.

问题回答

The most simple way I can think of:

<?php

if ($_REQUEST[ key ] ==  38lkjsdIEjrkd  && $_SERVER[ REMOTE_ADDR ] == 192.168.1.20) {

// load your web page

} else {

// show login or message about authentication

}

I hope that helps.

It seems to me that you are asking a general question about authentication and authorization for web pages.

There are, of course, many different ways to achieve this. You can setup a session based authentication system that requires the user to enter a valid username/password before accessing the page/script. This could be as simple as a login form that is presented when the user tries to access the page unless they are authenticated. You can then use PHP s built-in session management to persist the authentication across pages.

Alternatively, you could do authentication at the web server level, for example in Apache, through HTTP auth.

I second jonstjohn s opinion on HTTP authentication through creating a .htaccess (to allow only certain addresses to access the script) and .htpasswd (to define users who have access). However, this is true if you only need a quick solution for a few scripts.

If there are more scripts that require limited access, the best solution would be to create a class to take care of user logging and keep track of user session.

Generally speaking, embedding passwords and magic numbers in scripts is considered to be a bad coding style. Not to mention that those hard-coded "if"s are really hard to maintain.

Depends on the level of security you require. Basic Http Auth is simple to set up. See the manual.





相关问题
Run EXE from client side

I need run an exe file from client side. The Exe file exist in my C: Directory. I need run this exe file from my WEB site. How can I co this?

Security in PHP

I ve written some PHP scripts to do some server-side work on a headless linux server machine on a LAN. For example, I have http://ipadress/php/operations.php?operation=registerUser&uName=X&...

EMAIL server FSP model

For my assignment I need to develop FSP model for email server and client. I manage to write simple model which describes one user, server and his mailbox, but I am having problems changing this ...

Calling a service from a callback method in Client

I have a scenario where, upon receiving a command on one of the callback methods in client, the client needs to call another service. For example: In OnNewCommand() callback method client receives a ...

ServiceContractGenerator vs ServiceDescriptionImporter

I m trying to build a light-weight SOAP client without using Add Service Reference. Ideally, this client should work for as many services as possible. Currently, it uses ServiceDescriptionImporter to ...

Simple server and client request/response in C#

OK. I just want to know if this can be done. I m using C# asp.net language. I want to send a structure to a webserver from a webpage (much like you you can pass a structure to a function). The ...

热门标签