Jump to content

Security Question


sandrob57

Recommended Posts

You are wrong. This is why register_globals is highly recommended to be disabled on a server running php.

 

Reason being is that if you take straight data from a GET and put it into a database I can easily inject into your SQL.

 

Per say this codE:

 

url: http://www.yoururl.com/page.php?user='' OR 1 '  (don't quote me on this)

<?php

$sql = "SELECT * FROM users WHERE user = '".$user."'";
mysql_query($sql);
?>

 

Now the above may also depend on a few server settings, but it is always better safe than sorry. A better approach would be this:

 

url: http://www.yoururl.com/page.php?user='' OR 1 '  (don't quote me on this)

<?php
$user = mysql_real_escape_string($_GET['user']);  // escape any single quotes
$sql = "SELECT * FROM users WHERE user = '".$user."'";
mysql_query($sql);
?>

 

That way you know the code going into the database will not attempt to mess anything up.

 

--FrosT

Link to comment
https://forums.phpfreaks.com/topic/42085-security-question/#findComment-204133
Share on other sites

would this function prevent a variable from harming my database:

 

function stripinput($text) {

if (QUOTES_GPC) $text = stripslashes($text);

$search = array("\"", "'", "\\", '\"', "\'", "<", ">", " ");

$replace = array(""", "&#39;", "&#92;", """, "&#39;", "<", ">", " ");

$text = str_replace($search, $replace, $text);

return $text;

}

Link to comment
https://forums.phpfreaks.com/topic/42085-security-question/#findComment-204145
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.