cleaning inputs and outputs security

Started on the old forum in January 2012 · view the original in the archive · old links redirect here

#clean #dloadmax

No replies · 670 views · started 14 years ago · 1 min read

Jerson Developer · 70 posts #1
<?php
//////////////////////////http://dloadmax.com - free movies, mobile games, and pc games
//////////////clean
function escape($str) {
		$search=array("\\","\0","\n","\r","\x1a","'",'"');
    	        $replace=array("\\\\","\\0","\\n","\\r","\Z","\'",'\"');
    	        return str_replace($search,$replace,$str);
	}

	function clean($str) {
		$str = trim($str);				// Remove whitespace conditions
		$str = escape($str);				// Remove 99% mysql injection attacks
		$str = htmlspecialchars($str);
		$str = strip_tags($str);
		$str = stripslashes($str);
		$str = stripslashes($str);
		$str = addslashes($str);
		return $str;
	}
/////////////////////////////////////////////output
	function output($str) {
		$str = trim($str);				
		$str = strip_tags($str);
		$str = stripslashes($str);
		return $str;
	}
////////////////////////////////////////end of output
?>

output: form input echo clean($input);

display database data

echo output($data);

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close