Note that there are some explanatory texts on larger screens.

plurals
  1. POIs this enough for a secure site? (4 small functions)
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/4223980/php-the-ultimate-clean-secure-function">PHP: the ultimate clean/secure function</a> </p> </blockquote> <p>I revised my site's security filters today. I used to filter input and do nothing with the output. </p> <p>Here it is:</p> <p><strong>All user inputted variables go through these 2 functions depending on the type:</strong></p> <p><em>PS: Since I didn't start coding from scratch I did it for all variables, including the ones that aren't aren't used in queries. I understand that this is a performance killer and will be undoing that. Better safe than sorry right?</em></p> <pre><code>// numbers (I expect very large numbers) function intfix($i) { $i = preg_replace('/[^\d]/', '', $i); if (!strlen($i)) $i = 0; return $i; } // escape non-numbers function textfix($value) { $value = mysql_real_escape_string($value); return $value; } </code></pre> <p><strong>XSS preventing:</strong></p> <p>Input - filters user submitted text, like posts and messages. As you see it's currently empty. Not sure if strip_tags is needed.</p> <p>Output - on all html outputs</p> <pre><code>function input($input){ //$input = strip_tags($input, ""); return $input; } function output($bbcode){ $bbcode = textWrap($bbcode); // textwrap breaks long words $bbcode = htmlentities($bbcode,ENT_QUOTES,"UTF-8"); $bbcode = str_replace("\n", "&lt;br /&gt;", $bbcode); // then some bbcode (removed) and the img tag $urlmatch = "([a-zA-Z]+[:\/\/]+[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&amp;=\?\-_]+)"; $match["img"] = "/\[img\]".$urlmatch."\[\/img\]/is"; $replace["img"] = "&lt;center&gt;&lt;img src=\"$1\" class=\"max\" /&gt;&lt;/center&gt;"; return $bbcode; } </code></pre> <p>I included the img tag because it could be vulnerable to css...</p> <p>What do you think? Anything obviously wrong? Good enough?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload