Reputation: 1119
It's a well covered topic, but I'd like to get some confirmation on methods of using data from user variables, in a few different situations.
The variable is never used in a database, never stored, only displayed on screen for the user. Which function to use to make sure no html or javascript can screw things up?
The variable is taken into the database, and used in SQL queries.
The variable does both.
At the moment I xss_clean, and strip_tags. I've always done this, just by autopilot. Is there a better technique? Apologies if there's an identical question out there. I kinda assume there is, although I couldn't find one as thorough as this.
Cheers.
Upvotes: 3
Views: 10352
Reputation: 157989
One of worst delusions in the PHP world is that $_GET
or $_POST
have anything to do with security.
$_POST
, SOAP request or a database. It has to be ALWAYS the same: placeholders for the data, whitelisting for the everything else. $_POST
, SOAP request or a database.Upvotes: 4
Reputation: 293
$id="1;drop table users;"; $id=mysql_real_escape_string($id); $sql="SELECT * FROM table
WHERE id=$id";
Upvotes: -3
Reputation: 2345
References:
http://php.net/manual/en/function.htmlspecialchars.php
http://php.net/manual/en/function.mysql-real-escape-string.php
http://php.net/manual/en/book.pdo.php
http://php.net/manual/en/book.mysqli.php
Upvotes: -1
Reputation: 265864
htmlspecialchars
Upvotes: 5