473,395 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Weird: Slashes getting added

So, I've got this simple test PHP document (at the bottom of this
message). It simply puts up a textarea and then submits the form to
itself. The text of the textarea will be placed in 'body' of the $_POST
array. If the $_POST['body'] variable is set, it outputs what 'body'
contains and if not, it simply outputs 'No body var'.

Ok...like, I said...pretty simple.

Now, when I run this on my local machine, I enter:
we'll
in the textarea and when I submit the form, I get:
we'll
However, when I run this form on my webhost, I enter:
we'll
in the textarea and when I submit the form, I get:
we\'ll

Somehow a slash was added before the tick mark. Is this some
configuration option? Does it have to do with how PHP is configured on
the webhost? Does it have something to do with how Apache is configured
on the webhost? Any idea how the slash got there?

I'm just finding this rather odd and hoping to get an explanation.

If it is easily explained, is the best way to get rid of the extra slash
marks to call stripslashes()?

If you want to see it in action on the webhost, just visit:

http://www.ericgorr.net/slash

<?PHP
echo "<html><head><title>hello</title></head>";
echo "<body bgcolor=#eeeeee>";

if ( isset( $_POST['body'] ) )
{
echo $_POST['body'] . "<br>";
}
else
{
echo "No body var<br>";
}

echo "<form name=ContactPlayers method=post action=\"index.php\">";
echo "<textarea cols=80 name=body rows=12></textarea>";
echo "<br>";
echo "<p><input type=submit name=submit value=Send>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;";
echo "<input type=reset></p>";
echo "</form>";
echo "</body></html>";
?>
Feb 27 '06 #1
6 1676
On Mon, 27 Feb 2006 21:11:07 GMT, eg******@verizon.net (Eric) wrote:
However, when I run this form on my webhost, I enter:
we'll
in the textarea and when I submit the form, I get:
we\'ll

Somehow a slash was added before the tick mark. Is this some
configuration option? Does it have to do with how PHP is configured on
the webhost? Does it have something to do with how Apache is configured
on the webhost? Any idea how the slash got there?


It's the misguided PHP configuration option "magic_quotes_gpc".

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

This should be Off. Sounds like it's On on your webhost.

If you have permissions, you may be able to disable it in a .htaccess file.

Otherwise you'll have to mess around checking whether it's on or off, and if
it's on, use stripslashes() on the data, which is fairly ridiculous.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Feb 27 '06 #2
Andy Hassall <an**@andyh.co.uk> wrote:
On Mon, 27 Feb 2006 21:11:07 GMT, eg******@verizon.net (Eric) wrote:
However, when I run this form on my webhost, I enter:
we'll
in the textarea and when I submit the form, I get:
we\'ll

Somehow a slash was added before the tick mark. Is this some
configuration option? Does it have to do with how PHP is configured on
the webhost? Does it have something to do with how Apache is configured
on the webhost? Any idea how the slash got there?


It's the misguided PHP configuration option "magic_quotes_gpc".

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

This should be Off. Sounds like it's On on your webhost.

If you have permissions, you may be able to disable it in a .htaccess file.

Otherwise you'll have to mess around checking whether it's on or off, and if
it's on, use stripslashes() on the data, which is fairly ridiculous.


Thank you. This was driving me nuts.

Unfortunately, my webhost is rather clueless (I'm switching soon) and
likely won't be interested in modifying their configuration.
Feb 27 '06 #3
the other thing is that it's just a common way of storing a string,
it's called an escape character and can be used when normal use of a
character would end a string.
for instance:
the text; david said "hello" would need to become "david said
\"hello\"" so that php knew which quotes were the start and end of a
string and which werent... \ is php's signal that the character isnt
what it might seem to be so if you were to use \n it would give you a
line feed, \t is a tab and so on.

You can probably work this to your advantage if you just look it up in
the right reference :)

Feb 28 '06 #4
Eric wrote:
So, I've got this simple test PHP document (at the bottom of this
message). It simply puts up a textarea and then submits the form to
itself. The text of the textarea will be placed in 'body' of the $_POST
array. If the $_POST['body'] variable is set, it outputs what 'body'
contains and if not, it simply outputs 'No body var'.

Ok...like, I said...pretty simple.

Now, when I run this on my local machine, I enter:
we'll
in the textarea and when I submit the form, I get:
we'll
However, when I run this form on my webhost, I enter:
we'll
in the textarea and when I submit the form, I get:
we\'ll

Somehow a slash was added before the tick mark. Is this some
configuration option? Does it have to do with how PHP is configured on
the webhost? Does it have something to do with how Apache is configured
on the webhost? Any idea how the slash got there?

I'm just finding this rather odd and hoping to get an explanation.

If it is easily explained, is the best way to get rid of the extra slash
marks to call stripslashes()?

If you want to see it in action on the webhost, just visit:

http://www.ericgorr.net/slash

<?PHP
echo "<html><head><title>hello</title></head>";
echo "<body bgcolor=#eeeeee>";

if ( isset( $_POST['body'] ) )
{
echo $_POST['body'] . "<br>";
}
else
{
echo "No body var<br>";
}

echo "<form name=ContactPlayers method=post action=\"index.php\">";
echo "<textarea cols=80 name=body rows=12></textarea>";
echo "<br>";
echo "<p><input type=submit name=submit value=Send>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;";
echo "<input type=reset></p>";
echo "</form>";
echo "</body></html>";
?>

Hi

"magic_quotes_gpc" is turned on in the php.ini.

If you cannot change it, just add above EVERY script of yours:
ini_set("magic_quotes_gpc" , 0);

I took up the habbit of adding a file for every new project that contains a
few ini_sets, and if they fail, I let my app fail too.

It is the easiest way to overrule php.ini if you cannot or wish not to
change php.ini directly.
I think it is important to make such a file because you never know where
your application might end up. (Another ISP, or your current ISP changes
php.ini, etc.)

Remember that not all php.ini values can be overruled, so make sure you
check too if the ini_set() suceeded. (Like using ini_get() to check.)

Regards,
Erwin Moller
Feb 28 '06 #5

Erwin Moller wrote:
I took up the habbit of adding a file for every new project that contains a
few ini_sets, and if they fail, I let my app fail too.


I would be interested to know what ini_sets you considered to be
important.

Feb 28 '06 #6
er******@gmail.com wrote:

Erwin Moller wrote:
I took up the habbit of adding a file for every new project that contains
a few ini_sets, and if they fail, I let my app fail too.


I would be interested to know what ini_sets you considered to be
important.

Hi Eric,

The answer depends on the project.
But here is an example of how I do it.
This is piece of a script that gets included above every other script.

It simple defines the values I want to be sure of during the execution of my
scripts in that certain project.
Of course I could also try to overwrite ALL values in php.ini (that can can
overwritten with ini_set()), but these are the ones I picked.

---------------------------------
$iniSettings = array (
"short_open_tag" => "1",
// always on "track_vars" => "On",
"arg_separator.output" => "&",
"arg_separator.input" => "&",
"register_globals" => "0",

// magic quotes on
"magic_quotes_gpc" => "1",
"magic_quotes_runtime" => "0",
"register_argc_argv" => "1",

// max_execution_time defines the number of seconds a script may run
"max_execution_time" => "45",

// email stuff
"SMTP" => "smtp.xx.com",
"smtp_port" => "25",
// emailfrom not displayed here
"sendmail_from" => "XX@YY.com",

// Includepath!
"include_path" => ".;C:\Inetpub\wwwroot\XXXX\includes",

"default_mimetype" => "text/html",
"default_charset" => "ISO-8859-1",

// errorhandling
"error_reporting" => E_ALL,

// sessions
"session.save_handler" => "user",
"session.use_only_cookies" => "1",
"session.auto_start" => "0"
);
foreach ($iniSettings as $inikey => $inivalue){
ini_set($inikey, $inivalue);
// and test
if (ini_get($inikey) != $inivalue){
echo "UNRECOVERABLE INI-PROBLEM IN ini_settings.php.<br>";
echo "CANNOT SET $inikey to $inivalue.<br><h2>EXITING</h2>";
exit;
}
}

---------------------------------
Regards,
Erwin Moller
Mar 2 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sugapablo | last post by:
Ok. I have a web form with text fields. When the form is submitted, it goes to a php page to insert into a Postgres DB. Example: pg_query($db,"INSERT INTO table VALUES = ('" ....
1
by: Graham Thomson | last post by:
Hi, > > > > I've recently started looking at PHP and MY SQL within Dreamweaver MX. > > > > I'm usin PHPMyAdmin and put some example code from my tutorial book into it > > and pressed "Go". > >...
13
by: lawrence | last post by:
A user writes this sentence: "It was the New Urbanist's nightmare of sprawl run amok." They input that and my PHP script hits it with addslashes() and then the sentence gets put in the database....
16
by: droog | last post by:
Hello! I have just started learning python and encountered a problem. All I wanted to do, was to open a text file search and count the number of occurances of a single word and print that count....
7
by: Alex | last post by:
I'm new to Oracle, so this question may sound silly. I have been given a list of Oracle tables (they may be views, I'm not sure) that are available to me. I can run simple SQL select statements...
4
by: bdwise | last post by:
I have a textbox in a form, and I need to allow users to enter dates in US Format (MM/DD/YYYY). But they do not want to type any slashes, just 8 numbers, and have the slashes added for them. ...
0
by: Greenwich Support | last post by:
Hi All, I have a very weird problem which is occurring with a VB.Net app and PostgreSQL 7.3.1. There is a form that has a standard .Net datagrid on it that contains some data from a table in...
1
by: PeaceManGroove | last post by:
It's a long story, but our application needs to run in Access 97. All of the computers in our organisation also run Access 2003. . . C++ code launches our Access reports via a VB 6.0 program. ...
1
by: amitpatil | last post by:
Hello friends, I have a web form which holds fields containing special characters. On the next page when user submits those details, Information is shown with adding slashes to special...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.