Jump to content

catching malicious data??


srihari

Recommended Posts

A source of potential problems is considered a dynamic web application is the "polution" of input with bad, if not downright malicious data.

 

/* assumed $name is user data culled from a POSTed HTML form... */

$query = "SELECT * FROM members WHERE firstname = '" . $name ."';"

$result = mysql_query($query);

Can any one help me out??

How will i catch malformed (malicious?) POST/GET data in $name

can any one suggest me the how to proceede with code

can i have sample codes???

Link to comment
Share on other sites

$name = mysql_real_escape_string('name)

$query = "SELECT * FROM members WHERE firstname = '" . $name ."';"

$result = mysql_query($query);

whether this works out fine??? or

 

please check the below code also??

<?php

 

if (isset($_POST['first_name'])) {

    // Connect

 

    $link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password');

 

    if(!is_resource($link)) {

 

        echo "Failed to connect to the server\n";

        // ... log the error properly

 

    } else {

       

        // Reverse magic_quotes_gpc/magic_quotes_sybase effects on those vars if ON.

 

        if(get_magic_quotes_gpc()) {

            $last_name = stripslashes($_POST['last_name']);

          } else {

            $last_name = $_POST['last_name'];

          }

 

        // Make a safe query

        $query = sprintf("SELECT * FROM `customers` WHERE `last_name` = '%s'",

                        mysql_real_escape_string($last_name, $link);

                   

        mysql_query($query, $link);

 

        if (mysql_affected_rows($link) > 0) {

            echo "Product inserted\n";

        }

    }

} else {

    echo "Fill the form properly\n";

}

?>

 

Link to comment
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.