Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.