[SOLVED] Linux automatically adding slashes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

[SOLVED] Linux automatically adding slashes

Post by anjanesh »

Hi
I've come across this many times.
Im coding on WinXP (Apache) and uploading the scripts to a Linux Server.

If I send some data in the form of GET Linux is automatically adding slashes for which I have to do $_GET['a'] = stripslashes($_GET['a'])

test.php?a=h7w%C9%C2%22%26%C2N%7C%E5w%ED5

echo $_GET['a'];

On WinXP

Code: Select all

h7wÉÂ&quote;&ÂN|åwí5
On the Server (Linux)

Code: Select all

h7wÉÂ\&quote;&ÂN|åwí5
" converted to \"

All this time I thought that I'll need to use stripslashes() only after doing addslashes().
But now it seems I'll need to stip them even when I dont add them because Linux is adding them automatically.

What if the original string is h7wÉÂ\"&ÂN|åwí5 ?
stripslashes will work in Linux as the string will be h7wÉÂ\\\"&ÂN|åwí5 and the final string will be h7wÉÂ\"&ÂN|åwí5
But the same code on Windows will have the final string as h7wÉÂ"&ÂN|åwí5 getting rid of the \

Any idea on this ?

Thanks
Last edited by anjanesh on Thu Jul 07, 2005 7:39 am, edited 1 time in total.
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

maybe magic_quotes is on:
http://php.net/magic_quotes
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Ah..according to phpinfo
magic_quotes_gpc is On

How do I switch it off for my script ?

Thanks
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

you can strip_slashes();
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

It's all exlained here: http://www.php.net/magic_quotes
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Thanks. Solved.

Code: Select all

ini_set("magic_quotes_gpc","Off");
_quotes_gpc","Off");ic_quotes_gpc","Off");php]ini_set("magic_quotes_gpc","Off");ini_set("magic_quotes_gpc","Off");
Post Reply