website-secure-PHP

Cryptography is the process of changing the format of data (i.e., encrypting it) so that it is more difficult to read. Some cryptography, such as PGP, available for free for public use from http://www.pgp.com,  uses public and private keys in order to encode and decode information. Other cryptographic systems, like the crypt() function built into PHP will encrypt data but will not decrypt it. You can find out more about crypt() within the Strings section of the PHP manual.

Cryptography is just a part of a secure solution as it can only be used once data has been received by the server. You may also need to take advantage of SSL connections in your Web sites. SSL, which stands for Secure Sockets Layer, is a method of securely transmitting information between a client (the Web browser) and the server. Utilization of SSL connections (indicated by the https://prefix in a URL) is a must for e-commerce applications. You can also specify that cookies are sent over a SSL connection by setting the proper parameters when using the setcookie function. Check with your ISP or server administrator to see if SSL connections are supported on the machine you are using.

Passwords used within your PHP application should always be encrypted. If the server you are using does not support mcrypt(), use crypt() to encrypt the password entered during the login, then check this against the stored encrypted password.

While PHP does not have the same security concerns that you might find using CGI scripts or ASP, they still exist. There are a several considerations to keep in mind while programming.

The first recommendation I would make is that files which contain sensitive information such as passwords be placed outside of the Web document root. Every Web server application uses a folder as the default root for Web documents. Items within the folder can be accessed via a URL but items located above the default folder cannot be. However, they can still be used within PHP with the line:
require ("../secure.php");
The above line of code will include the file secure.php which is located one folder above the current document.

My second recommendation is a two-parter involving getting user submitted data from HTML forms. First you should always remember to use the POST form method (as opposed to GET) when transferring sensitive information. This is because the GET method will append the submitted data to the URL, making it visible in the Web browser window.
Second, you should be wary of user-submitted data because it can be a common loophole through which malicious users can wreak havoc with your system. Clever people may be able to insert JavaScript or executable code into your site using an HTML form. This code could send them sensitive information, alter databases, and so forth.

If you will be doing more than just basic Web development work, you ought to seriously consider learning more about Web security than the few points illustrated in this appendix.
There are literally dozens upon dozens of Web sites you can visit to keep yourself informed of pertinent security issues. The most prominent four, in my opinion, are:
There are also any number of books available ranging from those that generically discuss security to those that will assist in establish secure Windows NT or Linux Web servers.
With respect to PHP, do not forget to read the PHP manual's section on security. Also review the security section of the documentation for the database you are using on the server. Some, such as MySQL's manual, includes tips specifically with respect to using PHP and MySQL.






Related Posts:
  • codeigniter routes page The  routes.php filelets you remap URI requests to specific controller functions. For example, you may have a controller named sitewith a function named index. The URI for this controller/function combination might be… Read More
  • PHP Expressions An expression is the basic building block of the language.  Anything with a value can be thought of as an expression.  Examples include: 5 5+5 $a $a==5 sqrt(9) By combining many of these basic expressions, you… Read More
  • php-Dynamic Variables Sometimes it is useful to set and use variables dynamically.  Normally, you assign a variable like this:  $var = "hello";   Now let's say you want a variable whose name is the  value of the $var va… Read More
  • PHP-MySQL application Security With these two methods, there’s no longer any need to ever use GET for requests internal to an application. You may still need it for external requests, to other applications and web sites that aren’t coded to look for their… Read More
  • URL rewriting-various exercises-seo  Installing mod_rewrite Testing mod_rewrite Working with regular expressions Rewriting numeric URLs with two parameters Rewriting keyword-rich URLs Building a link factory Pagination and UR… Read More
  • Visualize Traffic with DIY Vector you will learn how to create your own traffic chart using the incredibly cool Canvas framework, which can produce vector graphics and animations with a little bit of HTML and JavaScript. All code referenced in this hack i… Read More
  • MySQL with php The basic steps of performing a query, whether using the mysql command-line tool or PHP, are the same:Connect to the database.Select the database to use.Build a SELECT statement.Perform the query.Display the results. Wh… Read More
  • Sorting Arrays-PHP PHP supports a variety of ways to sort an array when  I say sort, I am referring to an alphabetical sort if it is a string,  and a numerical sort if it is a number. When sorting an array,  you must k… Read More
  • what is CodeIgniter Helpers? Helpers, as their name implies, help you with specific tasks. Unlike libraries, helpers are not object -oriented but procedural in nature. Each helper contains one or more functions, each focusing on a specific task, with ze… Read More
  • var_dump and print_r -PHP-standard Functions like var_dump and print_r are also invaluable when debugging var_dump var_dump functions displays information about variables in a simple, readable  format. This function is very useful when debugging—p… Read More
  • security to POST-PHP $_POST  POST-method variables. Form field data from regular  POST-method forms.   PHP automatically creates variables for all the data it receives  in an HTTP request. This can include GET data, POST … Read More
  • PHP while Loop PHP while Loop with code while - loops run  a set of code as  the  condition is true. Basic Syntaxwhile (condition){    code for executed;}<?php$k=1;while($k<=5) {  echo "The numbe… Read More
  • how Installing mod_rewrite localhost If you’ve installed Apache yourself, read on. Because of its  popularity, mod_rewrite is now included with all common  Apache distributions. If desired, you can verify if your Apache installation has the mod_rewr… Read More
  • How to Enable mod_rewrite at Server mod_rewrite may not be enabled by default in your Apache configuration. To make sure,open the Apache configuration file, named httpd.conf. The full path of the file will be \Program Files\xampp\apache\conf\httpd.conf. Open … Read More
  • Building Dynamic Images-PHP You want to create an image based on a existing image template and dynamic data typically text). For instance, you want to create a hit counter. Load the template image, find the correct position to properly cente… Read More