Security for website

How to protect PHP website

Step 1: Storing data in mysql database.

If you want to get user data from user and store data into database, you always use addslashes() functions for every input. Users may add javascript code or iframe code in databases, so try to use strip_tags() function as well.

addslashes() :- Returns a string with backslashes in front of predefined characters

strip_tags() :- Strips HTML and PHP tags from a string. The strip_tags() function strips a string from HTML, XML, and PHP tags.Strip the string from HTML tags, but allow tags to be used:

File name : index.php

<?php
$str = "Who's itechtuto?";
echo $str . " i am not safe in a database query.<br>";
echo addslashes($str) . " i am safe in a database query.";
?>

<?php
echo strip_tags("Hello <b><i>world!</i></b>","<b>");
?>

<p>This function strips a string from HTML, XML, and PHP tags. In this example, we allow &lt;b&gt; tags to be used (all other tags will be removed).</p>

Output :-

Who's itechtuto? i am not safe in a database query.
Who\'s itechtuto? i am safe in a database query.

Step 2: printing data for user view

When ever you show data to user or output information, always user strip_tags() function and allow only div, p,br,strong,or font tags. Strip all other tags, otherwise, some user will insert malicious code in database and may iframe data or output javascript code

File name : index.php


Step 3: Session Handling.

Don?t store sensitive information in cookies.





Previous Next


Trending Tutorials




Review & Rating

0.0 / 5

0 Review

5
(0)

4
(0)

3
(0)

2
(0)

1
(0)

Write Review Here