SlideShare a Scribd company logo
1 of 11
10 Tips for Building a Secure 
PHP Application
Tip 1: Use Proper Error Reporting/Handling 
 The development process of the application can become very 
cumbersome when the errors are not handled properly. In other words if 
there are no error reports enabled then identifying the minor mistakes like 
spell checks, incorrect functions usage and many more mistakes can 
become very difficult. It is a great practice to enable error reporting before 
even starting the development process. Once the website goes live, just 
hide error reporting from displaying. 
 Set Below Code in PHP.ini file 
Log_errors = On 
Display_errors = Off 
 Set Below Code in 
Configuration file 
define('DEBUG',true); 
if(DEBUG ==true) 
{ 
ini_set('display_errors','On'); 
error_reporting(E_ALL); 
} 
else 
{ 
ini_set('display_errors','Off'); 
error_reporting(0); 
}
Tip 2: Validate Input 
 The inputs that are coming from the users needs to be validated from 
server side as well as client side. The inputs come in the form of POST or 
GET. Always use regular expressions in validation to avoid blank entries in 
the database. 
 Check the ‘type’ of the data 
 Check range of numbers 
 Check length of strings 
 Check emails , urls , dates to be valid 
 Ensure that data does not contain un allowed characters. 
For Example,if Month value is not valid 
if ( ! preg match( "/^[0-9]{1,2}$/", $_GET['month'] ) ) 
{ 
echo “”; // handle error 
}
Tip 3: Protecting Against Sql Injection 
 To perform your database queries, one should be using PHP Data 
Objects(PDO). With parameterized queries and prepared statements 
(Store Procedure), you can prevent SQL injection. 
 Take a look at the following example: 
<?php 
$sql = "SELECT * FROM users WHERE name=:name and age=:age"; 
$stmt = $db->prepare($sql); 
$stmt->execute(array(":name" => $name, ":age" => $age)); ?> 
 The code given above has two parameters named :name and :age. 
Prepare() is the method which informs the database engine to pre-compile 
the query and attach the values to the named parameters later. When 
execute() is called, the query is executed with the actual values of the 
named parameters. By coding this way, the attacker on the SQL wont be 
able to inject a malicious query because the queries are already 
precompiled and the database will not accept it. Hence a secure database 
can be achieved. 
 Mysql real escape string :- The mysql real escape string() function 
escapes special characters in a string for use in an SQL statement
Tip 4: Disable PHP’s Bad Features 
 Global Variables (Register Globals) 
 Using the PHP feature ‘Register Globals’ can hamper the objective of 
maintaining programming safety. As soon as this feature is activated in the 
PHP configuration file, even an uninitialized variable can lead to a 
damaging security flaw and the height is almost anyone can seize 
administrative control. To deal with this situation, disable Register Globals, 
ensure that you initialize variables as well as use localized variables too 
within the program. 
 If the application is running with register globals ON, a user could just 
place access=1 into a query string, and would then have access to 
whatever the script is running. 
 Unfortunately, we cannot disable register globals from the script side 
(using ini set, like we normally might), but we can use an .htaccess files to 
do this. 
 Set Below Code in .htaccessfile for disabling 
php flagregister globals 0 
 Set Below Code in php.ini file (if you have access for the same) for 
disabling 
register_globals = Off
Tip 5: Protect Against XSS Attacks 
 Cross Site Scripting has to be protected in order to protect a very simple 
attack on the website. PHP Application which allows the user inputs may 
come across a situation where the user placed a malicious script as per 
the example below into your application. 
 Here is an example of what an XSS attacker might submit to an 
application: 
<script>window.location.href='http://www.bad-location.com';</script> 
 What the script means is, it will hijack every user who visits that output 
page and send them to an unwanted page. This type of attack can be 
eliminated by using proper techniques to validate user input data and not 
allowing specific types of data. 
 Few functions to filter/validate data : 
htmlentities() ,strip_tags () , utf8_decode (), htmlspecialchars() , 
ctype_digit() , ctype_alnum(), stripslashes() , str_replace()
Tip 6: Avoid Short tags 
 <? and <?= are called short open tags, and are not always enabled. 
 PHP 5.3.0, they are disabled by default, however if they are enabled Set 
Below Code in PHP.ini file 
short_open_tag = Off 
 Your Application will not work if they are not enabled. 
Tip 7: Protect Against CSRF Attacks 
 CSRF stands for Cross Site Request Forgery. The attacker is the remote 
machine which is trying to access the cookies or some other means of a 
normal legitimate user. For example when the user is trying to comment 
on the website, the login information is primarily stored in the cookies and 
there is every possibility that the cookies can be accessed by remote 
server who is a malicious user. This is why it is imperative to use filters 
when requesting for random information. 
 Lets say a certain url in the application performs some database changes, 
update_info.php?id=123 
delete_record.php?id=123
 A hacker can setup a webpage with the following piece of code 
 <image(tag) source(tag)=”http://www.original-application. 
com/delete_record.php?id=123″ alt=”” /> 
 Ask the user to open this webpage. Now since the user is logged into the 
application the url will be triggered and whatever action necessary would 
be taken by the script.So basically a hacker has made the request through 
the user. This is “request forgery”. 
 Solution is to, enable the server to identify each request with a key/random 
value. 
Tip 8: Securing the session 
 Regenerate Session ID ( function:— session_regenerate_id(); ) 
Lock the user agent during a session 
 //Function to check if user is logged in or not 
functioncheck_login_status() 
{ 
if($_SESSION['logged'] == true and$_SESSION['old_user_agent'] == 
$_SERVER['HTTP_USER_AGENT'])
{returntrue;} 
returnfalse; 
} 
if(!check_login_status()) 
{ 
logout(); 
} 
 Lock the IP of a session 
$user_agent= @md5( $_SERVER['HTTP_ACCEPT_CHARSET'] . 
$_SERVER['HTTP_ACCEPT_ENCODING'] . 
$_SERVER['HTTP_ACCEPT_LANGUAGE'] . 
$_SERVER['HTTP_USER_AGENT'] . $_SERVER['REMOTE_ADDR']); 
 Store sessions in database 
 By default sessions are stored in files. Many applications are hosted on 
shared hosting environments where the session files are saved to /tmp 
directory. This directory may be readable to other users as well. If 
unencrypted the session information will be plain text in the file : 
userName|s:5:”ngood”;accountNumber|s:9:”123456789″; 
 Store sessions in database. Sessions stored inside database are not 
visible like files. They are only available to the application using it.
Tip 9: Setup correct directory permissions 
 Directories should have proper permissions with regard to the need of 
being writable or not. Keep a separate directory for temp files, cache files 
and other resource files and mark them writable as needed. Also 
directories (like temp) which can contain resource files, or files with other 
information should be guarded well and be totally inaccessible to the 
outside web. 
 Use htaccess to block all access to such directories( deny from all ) 
Tip 10: Password Security 
$salt = 'SUPER_SALTY'; 
$hash = md5($password . $salt); 
Original Source URL : http://www.techtic.com/blog/10-tips-for-building- 
a-secure-php-application/
Thank You 
Techtic Solutions 
PHP Development Company India 
Mail. info@techtic.com 
USA: +1 201-793-8324 
UK: +44 117 2308324 
AUS: +61 280 909 320

More Related Content

More from Techtic Solutions

Top 10 Marketing Automation Tools for eCommerce Stores.pptx
Top 10 Marketing Automation Tools for eCommerce Stores.pptxTop 10 Marketing Automation Tools for eCommerce Stores.pptx
Top 10 Marketing Automation Tools for eCommerce Stores.pptxTechtic Solutions
 
Why Having the Right Tech Stack is Critical for eCommerce?
Why Having the Right Tech Stack is Critical for eCommerce?Why Having the Right Tech Stack is Critical for eCommerce?
Why Having the Right Tech Stack is Critical for eCommerce?Techtic Solutions
 
8 Factors will Drive Fintech Growth in 2021
8 Factors will Drive Fintech Growth in 20218 Factors will Drive Fintech Growth in 2021
8 Factors will Drive Fintech Growth in 2021Techtic Solutions
 
Top 12 Advantages of Laravel Framework
Top 12 Advantages of Laravel FrameworkTop 12 Advantages of Laravel Framework
Top 12 Advantages of Laravel FrameworkTechtic Solutions
 
10 Common Applications of Artificial Intelligence in Healthcare
10 Common Applications of Artificial Intelligence in Healthcare10 Common Applications of Artificial Intelligence in Healthcare
10 Common Applications of Artificial Intelligence in HealthcareTechtic Solutions
 
What security measures do we take when working remotely?
What security measures do we take when working remotely?What security measures do we take when working remotely?
What security measures do we take when working remotely?Techtic Solutions
 
How Techtic Implements Seamless Project Management?
How Techtic Implements Seamless Project Management?How Techtic Implements Seamless Project Management?
How Techtic Implements Seamless Project Management?Techtic Solutions
 
Facts of Software Development
Facts of Software DevelopmentFacts of Software Development
Facts of Software DevelopmentTechtic Solutions
 
How to Integrate Mobile App with Website?
How to Integrate Mobile App with Website?How to Integrate Mobile App with Website?
How to Integrate Mobile App with Website?Techtic Solutions
 
10 On-demand App Statistics to look at During COVID-19
10 On-demand App Statistics to look at During COVID-1910 On-demand App Statistics to look at During COVID-19
10 On-demand App Statistics to look at During COVID-19Techtic Solutions
 
What’s new in Laravel 7.8?
What’s new in Laravel 7.8?What’s new in Laravel 7.8?
What’s new in Laravel 7.8?Techtic Solutions
 
Laravel Vs Django, Which Backend Framework is better?
Laravel Vs Django, Which Backend Framework is better?Laravel Vs Django, Which Backend Framework is better?
Laravel Vs Django, Which Backend Framework is better?Techtic Solutions
 
Differences between Mobile Apps and Websites – Techtic Solutions
Differences between Mobile Apps and Websites – Techtic SolutionsDifferences between Mobile Apps and Websites – Techtic Solutions
Differences between Mobile Apps and Websites – Techtic SolutionsTechtic Solutions
 
How to Integrate Mobile App with Website? – Techtic Solutions
How to Integrate Mobile App with Website? – Techtic SolutionsHow to Integrate Mobile App with Website? – Techtic Solutions
How to Integrate Mobile App with Website? – Techtic SolutionsTechtic Solutions
 
Advantages of Mobile Apps – Techtic Solutions
Advantages of Mobile Apps – Techtic SolutionsAdvantages of Mobile Apps – Techtic Solutions
Advantages of Mobile Apps – Techtic SolutionsTechtic Solutions
 
Design Thinking Myths - Techtic Solutions
Design Thinking Myths - Techtic SolutionsDesign Thinking Myths - Techtic Solutions
Design Thinking Myths - Techtic SolutionsTechtic Solutions
 
Why should you Develop Mockups? - Techtic Solutions
Why should you Develop Mockups? - Techtic SolutionsWhy should you Develop Mockups? - Techtic Solutions
Why should you Develop Mockups? - Techtic SolutionsTechtic Solutions
 
Best Laravel Eloquent Tips and Tricks
Best Laravel Eloquent Tips and TricksBest Laravel Eloquent Tips and Tricks
Best Laravel Eloquent Tips and TricksTechtic Solutions
 
6 Best Project Management Tools Comparison: Jira vs. Trello vs. MS Project vs...
6 Best Project Management Tools Comparison: Jira vs. Trello vs. MS Project vs...6 Best Project Management Tools Comparison: Jira vs. Trello vs. MS Project vs...
6 Best Project Management Tools Comparison: Jira vs. Trello vs. MS Project vs...Techtic Solutions
 
ReactJS Vs React Native: Understanding Differences, Advantages, Disadvantages
ReactJS Vs React Native: Understanding Differences, Advantages, DisadvantagesReactJS Vs React Native: Understanding Differences, Advantages, Disadvantages
ReactJS Vs React Native: Understanding Differences, Advantages, DisadvantagesTechtic Solutions
 

More from Techtic Solutions (20)

Top 10 Marketing Automation Tools for eCommerce Stores.pptx
Top 10 Marketing Automation Tools for eCommerce Stores.pptxTop 10 Marketing Automation Tools for eCommerce Stores.pptx
Top 10 Marketing Automation Tools for eCommerce Stores.pptx
 
Why Having the Right Tech Stack is Critical for eCommerce?
Why Having the Right Tech Stack is Critical for eCommerce?Why Having the Right Tech Stack is Critical for eCommerce?
Why Having the Right Tech Stack is Critical for eCommerce?
 
8 Factors will Drive Fintech Growth in 2021
8 Factors will Drive Fintech Growth in 20218 Factors will Drive Fintech Growth in 2021
8 Factors will Drive Fintech Growth in 2021
 
Top 12 Advantages of Laravel Framework
Top 12 Advantages of Laravel FrameworkTop 12 Advantages of Laravel Framework
Top 12 Advantages of Laravel Framework
 
10 Common Applications of Artificial Intelligence in Healthcare
10 Common Applications of Artificial Intelligence in Healthcare10 Common Applications of Artificial Intelligence in Healthcare
10 Common Applications of Artificial Intelligence in Healthcare
 
What security measures do we take when working remotely?
What security measures do we take when working remotely?What security measures do we take when working remotely?
What security measures do we take when working remotely?
 
How Techtic Implements Seamless Project Management?
How Techtic Implements Seamless Project Management?How Techtic Implements Seamless Project Management?
How Techtic Implements Seamless Project Management?
 
Facts of Software Development
Facts of Software DevelopmentFacts of Software Development
Facts of Software Development
 
How to Integrate Mobile App with Website?
How to Integrate Mobile App with Website?How to Integrate Mobile App with Website?
How to Integrate Mobile App with Website?
 
10 On-demand App Statistics to look at During COVID-19
10 On-demand App Statistics to look at During COVID-1910 On-demand App Statistics to look at During COVID-19
10 On-demand App Statistics to look at During COVID-19
 
What’s new in Laravel 7.8?
What’s new in Laravel 7.8?What’s new in Laravel 7.8?
What’s new in Laravel 7.8?
 
Laravel Vs Django, Which Backend Framework is better?
Laravel Vs Django, Which Backend Framework is better?Laravel Vs Django, Which Backend Framework is better?
Laravel Vs Django, Which Backend Framework is better?
 
Differences between Mobile Apps and Websites – Techtic Solutions
Differences between Mobile Apps and Websites – Techtic SolutionsDifferences between Mobile Apps and Websites – Techtic Solutions
Differences between Mobile Apps and Websites – Techtic Solutions
 
How to Integrate Mobile App with Website? – Techtic Solutions
How to Integrate Mobile App with Website? – Techtic SolutionsHow to Integrate Mobile App with Website? – Techtic Solutions
How to Integrate Mobile App with Website? – Techtic Solutions
 
Advantages of Mobile Apps – Techtic Solutions
Advantages of Mobile Apps – Techtic SolutionsAdvantages of Mobile Apps – Techtic Solutions
Advantages of Mobile Apps – Techtic Solutions
 
Design Thinking Myths - Techtic Solutions
Design Thinking Myths - Techtic SolutionsDesign Thinking Myths - Techtic Solutions
Design Thinking Myths - Techtic Solutions
 
Why should you Develop Mockups? - Techtic Solutions
Why should you Develop Mockups? - Techtic SolutionsWhy should you Develop Mockups? - Techtic Solutions
Why should you Develop Mockups? - Techtic Solutions
 
Best Laravel Eloquent Tips and Tricks
Best Laravel Eloquent Tips and TricksBest Laravel Eloquent Tips and Tricks
Best Laravel Eloquent Tips and Tricks
 
6 Best Project Management Tools Comparison: Jira vs. Trello vs. MS Project vs...
6 Best Project Management Tools Comparison: Jira vs. Trello vs. MS Project vs...6 Best Project Management Tools Comparison: Jira vs. Trello vs. MS Project vs...
6 Best Project Management Tools Comparison: Jira vs. Trello vs. MS Project vs...
 
ReactJS Vs React Native: Understanding Differences, Advantages, Disadvantages
ReactJS Vs React Native: Understanding Differences, Advantages, DisadvantagesReactJS Vs React Native: Understanding Differences, Advantages, Disadvantages
ReactJS Vs React Native: Understanding Differences, Advantages, Disadvantages
 

Recently uploaded

RT Nagar Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
RT Nagar Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...RT Nagar Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
RT Nagar Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...amitlee9823
 
AMBER GRAIN EMBROIDERY | Growing folklore elements | Root-based materials, w...
AMBER GRAIN EMBROIDERY | Growing folklore elements |  Root-based materials, w...AMBER GRAIN EMBROIDERY | Growing folklore elements |  Root-based materials, w...
AMBER GRAIN EMBROIDERY | Growing folklore elements | Root-based materials, w...BarusRa
 
infant assessment fdbbdbdddinal ppt.pptx
infant assessment fdbbdbdddinal ppt.pptxinfant assessment fdbbdbdddinal ppt.pptx
infant assessment fdbbdbdddinal ppt.pptxsuhanimunjal27
 
Top Rated Pune Call Girls Koregaon Park ⟟ 6297143586 ⟟ Call Me For Genuine S...
Top Rated  Pune Call Girls Koregaon Park ⟟ 6297143586 ⟟ Call Me For Genuine S...Top Rated  Pune Call Girls Koregaon Park ⟟ 6297143586 ⟟ Call Me For Genuine S...
Top Rated Pune Call Girls Koregaon Park ⟟ 6297143586 ⟟ Call Me For Genuine S...Call Girls in Nagpur High Profile
 
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...babafaisel
 
call girls in Vasundhra (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...
call girls in Vasundhra (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...call girls in Vasundhra (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...
call girls in Vasundhra (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...Delhi Call girls
 
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...SUHANI PANDEY
 
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)amitlee9823
 
Verified Trusted Call Girls Adugodi💘 9352852248 Good Looking standard Profil...
Verified Trusted Call Girls Adugodi💘 9352852248  Good Looking standard Profil...Verified Trusted Call Girls Adugodi💘 9352852248  Good Looking standard Profil...
Verified Trusted Call Girls Adugodi💘 9352852248 Good Looking standard Profil...kumaririma588
 
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...Call Girls in Nagpur High Profile
 
Design Inspiration for College by Slidesgo.pptx
Design Inspiration for College by Slidesgo.pptxDesign Inspiration for College by Slidesgo.pptx
Design Inspiration for College by Slidesgo.pptxTusharBahuguna2
 
(AISHA) Ambegaon Khurd Call Girls Just Call 7001035870 [ Cash on Delivery ] P...
(AISHA) Ambegaon Khurd Call Girls Just Call 7001035870 [ Cash on Delivery ] P...(AISHA) Ambegaon Khurd Call Girls Just Call 7001035870 [ Cash on Delivery ] P...
(AISHA) Ambegaon Khurd Call Girls Just Call 7001035870 [ Cash on Delivery ] P...ranjana rawat
 
VVIP CALL GIRLS Lucknow 💓 Lucknow < Renuka Sharma > 7877925207 Escorts Service
VVIP CALL GIRLS Lucknow 💓 Lucknow < Renuka Sharma > 7877925207 Escorts ServiceVVIP CALL GIRLS Lucknow 💓 Lucknow < Renuka Sharma > 7877925207 Escorts Service
VVIP CALL GIRLS Lucknow 💓 Lucknow < Renuka Sharma > 7877925207 Escorts Servicearoranaina404
 
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...amitlee9823
 
Best VIP Call Girls Noida Sector 44 Call Me: 8448380779
Best VIP Call Girls Noida Sector 44 Call Me: 8448380779Best VIP Call Girls Noida Sector 44 Call Me: 8448380779
Best VIP Call Girls Noida Sector 44 Call Me: 8448380779Delhi Call girls
 
Top Rated Pune Call Girls Saswad ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Saswad ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Saswad ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Saswad ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Call Girls in Nagpur High Profile
 
call girls in Kaushambi (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...
call girls in Kaushambi (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...call girls in Kaushambi (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...
call girls in Kaushambi (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...Delhi Call girls
 
💫✅jodhpur 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATISFACT...
💫✅jodhpur 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATISFACT...💫✅jodhpur 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATISFACT...
💫✅jodhpur 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATISFACT...sonalitrivedi431
 

Recently uploaded (20)

RT Nagar Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
RT Nagar Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...RT Nagar Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
RT Nagar Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bang...
 
AMBER GRAIN EMBROIDERY | Growing folklore elements | Root-based materials, w...
AMBER GRAIN EMBROIDERY | Growing folklore elements |  Root-based materials, w...AMBER GRAIN EMBROIDERY | Growing folklore elements |  Root-based materials, w...
AMBER GRAIN EMBROIDERY | Growing folklore elements | Root-based materials, w...
 
infant assessment fdbbdbdddinal ppt.pptx
infant assessment fdbbdbdddinal ppt.pptxinfant assessment fdbbdbdddinal ppt.pptx
infant assessment fdbbdbdddinal ppt.pptx
 
Top Rated Pune Call Girls Koregaon Park ⟟ 6297143586 ⟟ Call Me For Genuine S...
Top Rated  Pune Call Girls Koregaon Park ⟟ 6297143586 ⟟ Call Me For Genuine S...Top Rated  Pune Call Girls Koregaon Park ⟟ 6297143586 ⟟ Call Me For Genuine S...
Top Rated Pune Call Girls Koregaon Park ⟟ 6297143586 ⟟ Call Me For Genuine S...
 
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
 
call girls in Vasundhra (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...
call girls in Vasundhra (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...call girls in Vasundhra (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...
call girls in Vasundhra (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...
 
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance VVIP 🍎 SER...
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SER...Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SER...
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance VVIP 🍎 SER...
 
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
VIP Model Call Girls Kalyani Nagar ( Pune ) Call ON 8005736733 Starting From ...
 
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Basapura ☎ 7737669865☎ Book Your One night Stand (Bangalore)
 
Verified Trusted Call Girls Adugodi💘 9352852248 Good Looking standard Profil...
Verified Trusted Call Girls Adugodi💘 9352852248  Good Looking standard Profil...Verified Trusted Call Girls Adugodi💘 9352852248  Good Looking standard Profil...
Verified Trusted Call Girls Adugodi💘 9352852248 Good Looking standard Profil...
 
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
 
Design Inspiration for College by Slidesgo.pptx
Design Inspiration for College by Slidesgo.pptxDesign Inspiration for College by Slidesgo.pptx
Design Inspiration for College by Slidesgo.pptx
 
(AISHA) Ambegaon Khurd Call Girls Just Call 7001035870 [ Cash on Delivery ] P...
(AISHA) Ambegaon Khurd Call Girls Just Call 7001035870 [ Cash on Delivery ] P...(AISHA) Ambegaon Khurd Call Girls Just Call 7001035870 [ Cash on Delivery ] P...
(AISHA) Ambegaon Khurd Call Girls Just Call 7001035870 [ Cash on Delivery ] P...
 
VVIP CALL GIRLS Lucknow 💓 Lucknow < Renuka Sharma > 7877925207 Escorts Service
VVIP CALL GIRLS Lucknow 💓 Lucknow < Renuka Sharma > 7877925207 Escorts ServiceVVIP CALL GIRLS Lucknow 💓 Lucknow < Renuka Sharma > 7877925207 Escorts Service
VVIP CALL GIRLS Lucknow 💓 Lucknow < Renuka Sharma > 7877925207 Escorts Service
 
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
Jigani Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Bangal...
 
Best VIP Call Girls Noida Sector 44 Call Me: 8448380779
Best VIP Call Girls Noida Sector 44 Call Me: 8448380779Best VIP Call Girls Noida Sector 44 Call Me: 8448380779
Best VIP Call Girls Noida Sector 44 Call Me: 8448380779
 
Top Rated Pune Call Girls Saswad ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated  Pune Call Girls Saswad ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...Top Rated  Pune Call Girls Saswad ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
Top Rated Pune Call Girls Saswad ⟟ 6297143586 ⟟ Call Me For Genuine Sex Serv...
 
call girls in Kaushambi (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...
call girls in Kaushambi (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...call girls in Kaushambi (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...
call girls in Kaushambi (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝...
 
💫✅jodhpur 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATISFACT...
💫✅jodhpur 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATISFACT...💫✅jodhpur 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATISFACT...
💫✅jodhpur 24×7 BEST GENUINE PERSON LOW PRICE CALL GIRL SERVICE FULL SATISFACT...
 
B. Smith. (Architectural Portfolio.).pdf
B. Smith. (Architectural Portfolio.).pdfB. Smith. (Architectural Portfolio.).pdf
B. Smith. (Architectural Portfolio.).pdf
 

10 tips for building a secure php application

  • 1. 10 Tips for Building a Secure PHP Application
  • 2. Tip 1: Use Proper Error Reporting/Handling  The development process of the application can become very cumbersome when the errors are not handled properly. In other words if there are no error reports enabled then identifying the minor mistakes like spell checks, incorrect functions usage and many more mistakes can become very difficult. It is a great practice to enable error reporting before even starting the development process. Once the website goes live, just hide error reporting from displaying.  Set Below Code in PHP.ini file Log_errors = On Display_errors = Off  Set Below Code in Configuration file define('DEBUG',true); if(DEBUG ==true) { ini_set('display_errors','On'); error_reporting(E_ALL); } else { ini_set('display_errors','Off'); error_reporting(0); }
  • 3. Tip 2: Validate Input  The inputs that are coming from the users needs to be validated from server side as well as client side. The inputs come in the form of POST or GET. Always use regular expressions in validation to avoid blank entries in the database.  Check the ‘type’ of the data  Check range of numbers  Check length of strings  Check emails , urls , dates to be valid  Ensure that data does not contain un allowed characters. For Example,if Month value is not valid if ( ! preg match( "/^[0-9]{1,2}$/", $_GET['month'] ) ) { echo “”; // handle error }
  • 4. Tip 3: Protecting Against Sql Injection  To perform your database queries, one should be using PHP Data Objects(PDO). With parameterized queries and prepared statements (Store Procedure), you can prevent SQL injection.  Take a look at the following example: <?php $sql = "SELECT * FROM users WHERE name=:name and age=:age"; $stmt = $db->prepare($sql); $stmt->execute(array(":name" => $name, ":age" => $age)); ?>  The code given above has two parameters named :name and :age. Prepare() is the method which informs the database engine to pre-compile the query and attach the values to the named parameters later. When execute() is called, the query is executed with the actual values of the named parameters. By coding this way, the attacker on the SQL wont be able to inject a malicious query because the queries are already precompiled and the database will not accept it. Hence a secure database can be achieved.  Mysql real escape string :- The mysql real escape string() function escapes special characters in a string for use in an SQL statement
  • 5. Tip 4: Disable PHP’s Bad Features  Global Variables (Register Globals)  Using the PHP feature ‘Register Globals’ can hamper the objective of maintaining programming safety. As soon as this feature is activated in the PHP configuration file, even an uninitialized variable can lead to a damaging security flaw and the height is almost anyone can seize administrative control. To deal with this situation, disable Register Globals, ensure that you initialize variables as well as use localized variables too within the program.  If the application is running with register globals ON, a user could just place access=1 into a query string, and would then have access to whatever the script is running.  Unfortunately, we cannot disable register globals from the script side (using ini set, like we normally might), but we can use an .htaccess files to do this.  Set Below Code in .htaccessfile for disabling php flagregister globals 0  Set Below Code in php.ini file (if you have access for the same) for disabling register_globals = Off
  • 6. Tip 5: Protect Against XSS Attacks  Cross Site Scripting has to be protected in order to protect a very simple attack on the website. PHP Application which allows the user inputs may come across a situation where the user placed a malicious script as per the example below into your application.  Here is an example of what an XSS attacker might submit to an application: <script>window.location.href='http://www.bad-location.com';</script>  What the script means is, it will hijack every user who visits that output page and send them to an unwanted page. This type of attack can be eliminated by using proper techniques to validate user input data and not allowing specific types of data.  Few functions to filter/validate data : htmlentities() ,strip_tags () , utf8_decode (), htmlspecialchars() , ctype_digit() , ctype_alnum(), stripslashes() , str_replace()
  • 7. Tip 6: Avoid Short tags  <? and <?= are called short open tags, and are not always enabled.  PHP 5.3.0, they are disabled by default, however if they are enabled Set Below Code in PHP.ini file short_open_tag = Off  Your Application will not work if they are not enabled. Tip 7: Protect Against CSRF Attacks  CSRF stands for Cross Site Request Forgery. The attacker is the remote machine which is trying to access the cookies or some other means of a normal legitimate user. For example when the user is trying to comment on the website, the login information is primarily stored in the cookies and there is every possibility that the cookies can be accessed by remote server who is a malicious user. This is why it is imperative to use filters when requesting for random information.  Lets say a certain url in the application performs some database changes, update_info.php?id=123 delete_record.php?id=123
  • 8.  A hacker can setup a webpage with the following piece of code  <image(tag) source(tag)=”http://www.original-application. com/delete_record.php?id=123″ alt=”” />  Ask the user to open this webpage. Now since the user is logged into the application the url will be triggered and whatever action necessary would be taken by the script.So basically a hacker has made the request through the user. This is “request forgery”.  Solution is to, enable the server to identify each request with a key/random value. Tip 8: Securing the session  Regenerate Session ID ( function:— session_regenerate_id(); ) Lock the user agent during a session  //Function to check if user is logged in or not functioncheck_login_status() { if($_SESSION['logged'] == true and$_SESSION['old_user_agent'] == $_SERVER['HTTP_USER_AGENT'])
  • 9. {returntrue;} returnfalse; } if(!check_login_status()) { logout(); }  Lock the IP of a session $user_agent= @md5( $_SERVER['HTTP_ACCEPT_CHARSET'] . $_SERVER['HTTP_ACCEPT_ENCODING'] . $_SERVER['HTTP_ACCEPT_LANGUAGE'] . $_SERVER['HTTP_USER_AGENT'] . $_SERVER['REMOTE_ADDR']);  Store sessions in database  By default sessions are stored in files. Many applications are hosted on shared hosting environments where the session files are saved to /tmp directory. This directory may be readable to other users as well. If unencrypted the session information will be plain text in the file : userName|s:5:”ngood”;accountNumber|s:9:”123456789″;  Store sessions in database. Sessions stored inside database are not visible like files. They are only available to the application using it.
  • 10. Tip 9: Setup correct directory permissions  Directories should have proper permissions with regard to the need of being writable or not. Keep a separate directory for temp files, cache files and other resource files and mark them writable as needed. Also directories (like temp) which can contain resource files, or files with other information should be guarded well and be totally inaccessible to the outside web.  Use htaccess to block all access to such directories( deny from all ) Tip 10: Password Security $salt = 'SUPER_SALTY'; $hash = md5($password . $salt); Original Source URL : http://www.techtic.com/blog/10-tips-for-building- a-secure-php-application/
  • 11. Thank You Techtic Solutions PHP Development Company India Mail. info@techtic.com USA: +1 201-793-8324 UK: +44 117 2308324 AUS: +61 280 909 320