Jump to content

Too much security?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
Surpintine

Surpintine

    Newbie

  • Members
  • Pip
  • 4 posts
Is this overkill?


$var = $_GET['variable'];

$var = htmlentities($var);

$var = stripslashes($var);

$var = mysqli_real_escape_string($var);


and should it be in a different order?

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
It depends on what you'll be doing with $var after that.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
Yes, it will encode any HTML entities into their entity form, which may break some database operations if it relies on raw entities.

If you are displaying it, only use:

  • htmlentities()

If you are placing it into a database query:

  • mysql*_real_escape_string().

A simple notice is if you strip slashes without them being required to be stripped, you may destroy data (if a slash is contained in a password, or an external document for example). It is only required on database operations if Magic Quotes (magic_quotes_gpc) is turned on, which will add quotes automatically (thus breaking _real_escape_string)

Edited by Alexander, 24 June 2010 - 08:01 PM.

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#4
Surpintine

Surpintine

    Newbie

  • Members
  • Pip
  • 4 posts
Thanks a bunch.

#5
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
You're welcome.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.