IT Community - Software Programming, Web Development and Technical Support

Secure PHP code

This is a discussion on Secure PHP code within the PHP Programming forums, part of the Web Development category; I am going explain about some of the security measures that you have to note for securing your php. Configure ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 01-14-2008, 03:29 AM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 803
vadivelanvaidyanathan is on a distinguished road
Wink Secure PHP code

I am going explain about some of the security measures that you have to note for securing your php.

Configure your php.ini

php.ini is the configuration file of PHP. Its has a number of variables. You can set the values of these variables for making your php scripts more secure. Here am explaining some of the them.

1) display_errors

Disable the display_errors is the first thing. If it is ' On ' the errors on execution will be displayed to the user's browser window. So the user can get an idea about the table structure and directory structure. You can avoid this by disabling display_errors in php.ini

Usage : display_errors=OFF


2) safe_mode
safe_mode is more relevent in a shared server environment. If safe_mode is enabled it will check a UID/GID comparison check on the file/directory to be accessed and compare it to the uid/gid of the script that is trying to access the file. If that are same it will allow the file access if not it will block the access. If you want to compare only GID then you can enable " safe_mode_gid" value in php.ini .

3)sql.safe_mode

Make sql.safe_mode as Off. If it is on mysqli_connect() and mysql_connect() will connect to mysql with default username and password.

4)magic_quotes_gpc

Enable magic_quotes_gpc so that you can make your user inputs secure. It work s same as addslashes() function. It will add a backslash (\) with every single quotes, double quotes.

5)safe_mode_allowed_env_vars and safe_mode_allowed_env_vars

These two variables will protect environment variables from changing using user php scripts. The field safe_mode_allowed_env_vars contains a list of prefixes that identify the names of the environment variables the user is allowed to change. So that environment variables which are not starting with one of them defined in safe_mode_allowed_env_vars cannot be modified.

Another configuration safe_mode_protected_env_vars will set the names of environment variables that the user is not allowed to modify even if it is present in safe_mode_allowed_env_vars.

6)disable_functions

This will allow you to disable the insecure functions such as shell_exec, system,exec.

Take your own logical measures

Besides all these you can take your own security measures while writing php scripts. For example always store your passwords as hashed values. PHP has inbuilt hashing function named md5() and sha1 . md5() is a 128-bit and sha1() is a 160-bit hashing algorithm. If you use this hashing techniques you can save your passwords and important data from hackers even though your databases are compromised.

Always test your codes for different type of inputs and search for any security flaws. Keep in mind that every user input to your php scripts can be malicious. We cannot make our scripts a perfect one but always try for that.
__________________
V.Vadivelan

There never a wrong time to do the right thing.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-30-2008, 04:58 AM
shirry shirry is offline
D-Web Trainee
 
Join Date: Sep 2008
Posts: 3
shirry is on a distinguished road
Default Re: Secure PHP code

is really useful for me, I am glad to read it here.
__________________
business cards printing
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-01-2008, 10:21 PM
simrita simrita is offline
D-Web Trainee
 
Join Date: Sep 2008
Posts: 21
simrita is on a distinguished road
Default Re: Secure PHP code

PHP is a computer scripting language. Originally designed for producing dynamic web pages, it has evolved to include a command line interface capability and can be used in standalone graphical applications.

___________________

womens perfume Sexual Predators
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-06-2008, 12:17 AM
danica danica is offline
D-Web Trainee
 
Join Date: Sep 2008
Posts: 18
danica is on a distinguished road
Default Re: Secure PHP code

PHP is a widely-used general-purpose scripting language that is especially suited for web development and can be embedded into HTML. It generally runs on a web server, taking PHP code as its input and creating web pages as output. It can be deployed on most web servers and on almost every operating system and platform free of charge.

_________________

online betting gourmet food
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 11-17-2008, 12:53 AM
pink99 pink99 is offline
D-Web Trainee
 
Join Date: Nov 2008
Posts: 3
pink99 is on a distinguished road
Default security measures while writing php

Besides all these you can take your own security measures while writing php scripts. For example always store your passwords as hashed values. PHP has inbuilt hashing function named md5() and sha1 . md5() is a 128-bit and sha1() is a 160-bit hashing algorithm. If you use this hashing techniques you can save your passwords and important data from hackers even though your databases are compromised.
__________________
vaporizer review
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Secure your Web server Jeyaseelansarc Server Management 39 03-28-2008 02:19 AM
How To Secure Windows XP arjkhanna Operating Systems 10 02-06-2008 07:01 AM
How To Secure Network arjkhanna Networking & Internet Connectivity 5 01-21-2008 09:59 AM
How To Secure Windows XP arjkhanna Operating Systems 0 01-08-2008 09:18 AM
Secure Appn sudhir Software Testing 2 04-16-2007 04:08 AM


All times are GMT -7. The time now is 06:57 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0