/    Sign up×
Community /Pin to ProfileBookmark

Inserting data to mysql databse

Hello guys
Recently I changed the forms I use in my websites and the text editor, from the “spaw editor” to the most commonly used “fckeditor”. PLUS I changed the hosting company I used for years. Magic quotes here are enabled, while they weren’t on the old one… So I’m starting making some general changes

Should I convert special characters like
‘ to ‘
” to "
& to &
< to &lt;

etc, before entering them to the database?
Also, I should have a proper function that check magic quotes…? Like

function custom_addslashes($string){
$string = htmlspecialchars($string);
if (get_magic_quotes_gpc()==1)
return ($string);
else
return (addslashes($string));
}

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@eval_BadCode_Nov 15.2011 — You can just edit your php.ini flle and add a new line with

[CODE]
magic_quotes_gpc = 0
[/CODE]


If you don't have a php.ini file (a configuration file) you should create one.

You can check that it's configured correctly with:

[code=php]
print_r(ini_get_all('magic_quotes_gpc));
[/code]


0 is false or OFF

1 is true or ON

[global_value] means what it's default value is. On your old host this was set to 0, on your new host it's most likely 1, if it isn't 1 then your local value is.

[local_value] means what PHP is configured to use at the time PHP ran the ini_get_all() method.

[Access] is talking about where you are allowed to change this from configuration setting from.

1 would be global. (sysadmin can set this in the main php.ini).


2 would be local (your php.ini files)

4, yes i mean 4 not 3, would be inside of the php script. EX:
[code=php]<?php ini_set('magic_quotes_gpc', false); ?>[/code]

The reason it is 4 and not 3 for the third value is because these are bits (binary). The idea is that any combination can exist and have it's own unique number. Consider these scenarios

000 0

001 1

010 2

011 3

100 4

101 5

110 6

111 7

0 means you should question the php developer's logic,

1 means the sys admin (root) can edit it.

2 means you can edit it inside of php.ini

3 is 1 + 2

4 can be set inside of the php script itself

5 is 1 + 4

6 is 2 + 4

7 is 1 + 2 + 4


If you don't know how to create a php.ini file, it's literally a file called php.ini. The configurations will be applied to files in the same directory as the directory you create the file in, and all of it's sub directories unless you overwrite it with another php.ini file in that subdirectory or inside of the script with ini_set()

If you don't understand anything I said just run this add this code to the top of the problem script and request the page once.
[code=php]<?php

$gpc = ini_get_all(''magic_quotes_gpc');
if($gpc['Global']) echo "magic quotes are on by default.";
if($gpc['Local']) echo 'magic quotes are currently on';
if($gpc['Access']) &#37; 2 == 0) {
$h = fopen("php.ini","a");
fwrite($h, "
magic_quotes_gpc = 0
");
)
fclose($h);
?>
[/code]
×

Success!

Help @mrknowitall spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...