Page 1 of 1

Failing to post a textarea with <br> in it

Posted: Mon Jun 04, 2007 4:06 am
by emalrola
I have changed hosts and my (previously-working) php code is now failing.

Basically I have a very simple

<form action='../cgi-bin/preview.pl' method=post>
<textarea name='textx'></textarea>
</form>

All is fine if I just enter simple words into the textarea. However if I enter 'gggh<br>fsdafgjsa' for example, it just seems to crumble in a heap! the perl script does not even get called and I jump back to the index page of the website. It seems that the post is just not working. Any ideas? I have tried replacing the action but still the same - it just doesn't seem to be getting that far.

Host is linux, php version 4.4.3

Any help appreciated - it's driving me mad!

Posted: Mon Jun 04, 2007 6:48 am
by blackbeard
Try using htmlentities and html_entity_decode.

Posted: Mon Jun 04, 2007 7:57 am
by feyd
If it's breaking, it would be on Perl's doorstep, not PHP's.

Why perl?

Posted: Mon Jun 04, 2007 8:48 am
by emalrola
Sorry, can you explain a bit more about the perl comment (or point me in the right direction). I obviously don't understand where the error is - I have tried changing the action to 'x.html' where x.html is a simple bit of text to display and even that doesn't work as soon as I type in <br> within the input string. Have also tried changing the textarea to <input> and it still fails then.

It's as if whatever is trying to post the variables is just failing when there is a '<br>' in the string., but I don't know how to find out exactly what is failing and what to change....

Posted: Mon Jun 04, 2007 8:55 am
by blackbeard
Sorry, didn't see that it was going to a perl script.

From your last question, is this a script you wrote yourself, or it is something that was done for you?

Posted: Mon Jun 04, 2007 9:00 am
by emalrola
It is a script I wrote, but the problem is not with the script! For example, I can chmod the permissions on (or even delete) the script, and if I try to POST a varible from the php with a '<br>' somewhere in the script, it just jumps straight to the site's index page. If I POST a variable from the php with no '<br>' then I get the expected result - file not found or server permissions. I'm sure it has to do with my new host's set up - this code was working absolutely fine for 2 years on my previous host.... They are both using the same versions of php/apache etc so I think it colud be a php ini problem, but I've got no idea what to check/how to even debig this error...

Thanks for your time

Posted: Mon Jun 04, 2007 9:04 am
by feyd
You will need to post more code or something more tangible. At this point, it's just not possible to guess at a culprit.

More than likely, it has nothing to do with PHP. PHP doesn't care what's in the submission content. Your host may have some filtering (like a security filter) that may be blocking it. Have you talked to them?

Posted: Mon Jun 04, 2007 9:14 am
by emalrola
Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


This is the simplest code that illustrates what is happening:


source file:

Code: Select all

<?php header("Content-type: text/html; charset=iso-8859-1") ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html lang=en>
<head>
</head>
<body>
<form action="j.php" method=post>
<input name="test"></input>
<input type=submit Value="Preview"></input>
</form>
</body>
</html>
j.php:

Code: Select all

<?php header("Content-type: text/html; charset=iso-8859-1") ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html lang=en>
<head>
</head>
<body>
It worked
</body>
</html>


Running source - if type dsgakgfkdasj into input, hit submit, get 'It worked' (as expected)
If type in gfadskg<br>hfsakhjkfas, hit submit - get taken to home page of site with no error logging or hints as to what has happened...


Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Jun 04, 2007 10:27 am
by maliskoleather
my guess is that for some reason or another, you're getting a 404 error, and its redirecting you to the index.

rename your .htaccess to something like x.htaccess for now, then reload the page and see what happens.

Posted: Mon Jun 04, 2007 10:57 am
by blackbeard
Possibly checking for XSS????

Posted: Mon Jun 04, 2007 11:30 am
by RobertGonzalez
If request data is breaking server side processing I would guess the server is the place to check first. If you enter a <br> and neither the perl script nor the PHP script get called, then something is happening before to the call to the processing on those pages. Since both perl and PHP sit on the server, I would suspect it has something to do with the server.

Server anti-spam utility to blame

Posted: Sun Jun 10, 2007 5:45 pm
by emalrola
Turns out the ISP has anti-spam/anti-hacking code switched on by default to stop anything which could be embedded html being input.

Thanks everyone for your helpful suggestions and at least I know that my code wasn't to blame!