Guest PHP - Magic Quotes - elite411 - PHP - Magic Quotes - elite411
Main
Registration
Login
Main | signup | loginsend free smsPhotoshopGalleryGallery
Our Link Exchange Code:
Now translate our website in any language
[ New messages · Members · Forum rules · Search · RSS ]
Page 1 of 11
elite411 » Programming » PHP » PHP - Magic Quotes
PHP - Magic Quotes
farhan411Date: Tuesday, 2010-07-06, 5:46 PM | Message # 1
Website Owner
Group: Administrators
Messages: 930
Awards: 23 Load ...
Reputation: 62
Status: Offline
PHP - Magic Quotes

Prior to PHP 6 there was a feature called magic quotes that was created to help protect newbie programmers from writing bad form processing code. Magic quotes would automatically escape risky form data that might be used for SQL Injection with a backslash \. The characters escaped by PHP include: quote ', double quote ", backslash \ and NULL characters.

Magic Quotes - Are They Enabled?


First things first, you need to check to see if you have magic quotes enabled on you server.
The get_magic_quotes_gpc function will return a 0 (off) or a 1 (on). These boolean values
will fit nicely into an if statement where 1 is true and 0 is false.

PHP Code:

if(get_magic_quotes_gpc()) 
echo "Magic quotes are enabled";
else
echo "Magic quotes are disabled";

Display:


Magic quotes are enabled

If you received the message "Magic quotes are enabled" then you should definitely
continue reading this lesson, if not feel free to learn about it in case you
are developing for servers that might have quotes on or off.

Magic Quotes in Action


Now lets make a simple form processor to show how machines with magic quotes
enabled will escape those potentially risky characters. This form submits to itself, so
you only need to make one file, "magic-quotes.php" to test it out.

magic-quotes.php Code:

<?php 
echo "Altered Text: ".$_POST['question'];
?>

<form method='post'>
Question: <input type='text' name='question'/><br />
<input type='submit'>

</form>

This simple form will display to you what magic quotes is doing. If you were to
enter and submit the string: Sandy said, "It's a beautiful day outside and I like to use \'s."
You would receive the following output.

Display:

Altered Text: Sandy said, \"It\'s a beautiful day outside and I like to use \\\'s.\"


Question:


Magic quotes did a number on that string, didn't it? Notice that
there is a backslash before all of those risky characters we talked about earlier.
After magic quotes:



  • A backslash \ becomes \\

  • A quote ' becomes \'
  • A double-quote " becomes \"

Now say that you wanted to remove the escaping that magic quotes puts in, you have two options:
disable magic quotes or strip the backslashes magic quotes adds.

Removing Backslashes - stripslashes()


Before you use PHP's backslash removal function stripslashes it's smart
to add some magic quote checking like our "Are They Enabled?" section above. This way
you won't accidentally be removing slashes that are legitimate in the future if
your PHP's magic quotes setting changes in the future.

magic-quotes.php Code:

<?php 
echo "Removed Slashes: ";

// Remove those slashes
if(get_magic_quotes_gpc())
echo stripslashes($_POST['question']);
else
echo $_POST['question'];


?>

<form method='post'>
Question: <input type='text' name='question'/><br />
<input type='submit'>

</form>

Our new output for our string containing risky characters would now be:

Display:


Removed Slashes: Sandy said, "It's a beautiful day outside and I like to use \'s."

Question:






Click here to Visit us


elite411
www.farhan411.do.am
HTML code to this post
BB-code to this post
Direct link to this post
 
elite411 » Programming » PHP » PHP - Magic Quotes
Page 1 of 11
Search:
User's Color: [Administrator] [Checked] [SuperModerator] [Vip] [G.Mod] [user]
++++++++++Get cash from your website. Sign up as affiliate.+ +Earn Rs. 9,000 Click here:Join now! Your Adds here.
Statistics Forum
Recent Posts Readable topic Top Users New User Last user Login
  • selling cc cvv2 fulls tracks 1 and 2 dumps (1)
  • selling cc cvv2 fulls... (0)
  • selling cc cvv2 fulls tracks 1 and 2 dumps (0)
  • selling cc cvv2 fulls tracks 1 and 2 dumps (0)
  • Admin Contact: (0)
  • Windows 7 Gamer Edition | 64-bit | UNDEADCROWS-ISO (0)
  • new title bar (7)
  • Hide IP Easy 4.1.6.6 (13)
  • User Ranks (4)
  • My heart will go on-'Titanic' (5)
  • selling cc cvv2 fulls tracks 1 and 2 dumps (1)
  • selling cc cvv2 fulls... (0)
  • selling cc cvv2 fulls tracks 1 and 2 dumps (0)
  • selling cc cvv2 fulls tracks 1 and 2 dumps (0)
  • Admin Contact: (0)
  • Windows 7 Gamer Edition | 64-bit | UNDEADCROWS-ISO (0)
  • new title bar (7)
  • Hide IP Easy 4.1.6.6 (13)
  • User Ranks (4)
  • My heart will go on-'Titanic' (5)
  • farhan411
  • Hacking_skills
  • zeeleey
  • Hacker4Life
  • Fantasy
  • Deep_Thinking_4u
  • ELIA
  • Admin
  • Ilia_ano1
  • NiKoLa
  • stormseller
  • ayukodok
  • dafaggotry
  • mas
  • Ghaniz
  • maxwell99
  • cms_star
  • ahmet28051
  • Fiat
  • love
  • Copyrights farhan411 © 2011
    Hosted by Farhan Khalid