Jump to content

Recommended Posts

I have the following slice of PHP that inserts data into the database and is later called into a page. I understand I need to use the get_magic_quotes() function to stop people from inserting javascript for example into the page when the data is called back. How do I go about this?

 

<?php
$profileID = $_POST["profileID"];
$comment = $_POST["commentBox"];
$poster = $_POST["poster"];

loginDetails();

$query = "INSERT INTO comments SET id = '$profileID', comment = '$comment', poster = '$poster' ";

$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
echo "<h4>Comment added<h4>";
?>

Link to comment
https://forums.phpfreaks.com/topic/52370-magic-quotes/
Share on other sites

Well, not exactly.  The function is get_magic_quotes_gpc(), and it only returns whether or not magic quotes are on.  You should use an escaping function such as mysql_real_escape_string() when putting user-generated data into your database.  Magic quotes are usually more trouble than they're worth, and the benefit of the get_magic_quotes_gpc() function is to stripslashes() if it returns true before applying the escape function and inserting the data.

 

http://www.php.net/manual/en/security.magicquotes.php

http://www.php.net/manual/en/function.mysql-real-escape-string.php

Link to comment
https://forums.phpfreaks.com/topic/52370-magic-quotes/#findComment-258440
Share on other sites

<?php
function myEscape($string) {
       return get_magic_quotes_gpc()?addcslashes(stripslashes($string), "\x00\n\are\\'\"\x1a"):addcslashes($string, "\x00\n\are\\'\"\x1a");
}

$profileID = myEscape($_POST["profileID"]);
?>

 

The above code simulates mysql_real_Escape_string without having to have a DB connection.

 

Link to comment
https://forums.phpfreaks.com/topic/52370-magic-quotes/#findComment-258453
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.