|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
// there is
define('VALID_MESSAGE', '/^[a-zA-Z0-9 ,.!?\n]{1,10000}$/'); // there is function validate($variable, $name, $valid, $name2, $inornot) // there is if (!preg_match($valid, $variable)) { $_SESSION["trying"]="The ".$name." is invalid!"; return false; } // it accepts testtesttesttesttesttest // it refuses testtest testtest testtest Why? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
// there is too
if (!validate($subject, "subject", VALID_SUBJECT, $subject2, "in")) { header ("Location: create.php"); On Jun 20, 4:08pm, Raistlin Majere <pedbe...@gmail.com> wrote: > // there is > > define('VALID_MESSAGE', '/^[a-zA-Z0-9 ,.!?\n]{1,10000}$/'); > > // there is > > function validate($variable, $name, $valid, $name2, $inornot) > > // there is > > if (!preg_match($valid, $variable)) { > $_SESSION["trying"]="The ".$name." is invalid!"; > return false; > > } > > // it accepts > > testtesttesttesttesttest > > // it refuses > > testtest > testtest > testtest > > Why? |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Fri, 20 Jun 2008 21:08:24 +0200, Raistlin Majere <pedbessa@gmail.com>
wrote: > define('VALID_MESSAGE', '/^[a-zA-Z0-9 ,.!?\n]{1,10000}$/'); > // it accepts > testtesttesttesttesttest > > // it refuses > testtest > testtest > testtest Most likely, because of \r. An obvious solution would be: define('VALID_MESSAGE','/^[a-z0-9,.!?\s]{1,10000}$/i'); Allthough I'd rather use a (mb_)strlen() & '/^[a-z0-9,.!?\s]+$/i' for some reason. I have no idea wether that's more efficient or not, or even why I prefer it... -- Rik Wasmus ....spamrun finished |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
it still says the message is invalid
On Jun 20, 4:17pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote: > On Fri, 20 Jun 2008 21:08:24 +0200, Raistlin Majere <pedbe...@gmail.com> > wrote: > > > define('VALID_MESSAGE', '/^[a-zA-Z0-9 ,.!?\n]{1,10000}$/'); > > // it accepts > > testtesttesttesttesttest > > > // it refuses > > testtest > > testtest > > testtest > > Most likely, because of \r. > An obvious solution would be: > define('VALID_MESSAGE','/^[a-z0-9,.!?\s]{1,10000}$/i'); > > Allthough I'd rather use a (mb_)strlen() & '/^[a-z0-9,.!?\s]+$/i' for some > reason. I have no idea wether that's more efficient or not, or even why I > prefer it... > -- > Rik Wasmus > ...spamrun finished |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Fri, 20 Jun 2008 21:43:05 +0200, Raistlin Majere <pedbessa@gmail.com>
wrote: > On Jun 20, 4:17pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote: >> On Fri, 20 Jun 2008 21:08:24 +0200, Raistlin Majere >> <pedbe...@gmail.com> >> wrote: >> >> > define('VALID_MESSAGE', '/^[a-zA-Z0-9 ,.!?\n]{1,10000}$/'); >> > // it accepts >> > testtesttesttesttesttest >> >> > // it refuses >> > testtest >> > testtest >> > testtest >> >> Most likely, because of \r. >> An obvious solution would be: >> define('VALID_MESSAGE','/^[a-z0-9,.!?\s]{1,10000}$/i'); Please don't toppost. > it still says the message is invalid Not here it doesn't: <?php $variable = 'tasdtasd asdasd asdasd asdasd'; $valid = '/^[a-z0-9,.!?\s]{1,10000}$/'; echo preg_match($valid, $variable) ? 'valid' : 'invalid'; ?> Outputs:valid If you made sure the right regex & variable arrived at your function, i'd be interested in this output: for($i = 0;$i < strlen($variable) ; $i++){ echo $variable[$i].'='.ord($variable[$i])."\n"; } -- Rik Wasmus |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On Jun 20, 4:50pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote:
> On Fri, 20 Jun 2008 21:43:05 +0200, Raistlin Majere <pedbe...@gmail.com> > wrote: > > > > > On Jun 20, 4:17pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote: > >> On Fri, 20 Jun 2008 21:08:24 +0200, Raistlin Majere > >> <pedbe...@gmail.com> > >> wrote: > > >> > define('VALID_MESSAGE', '/^[a-zA-Z0-9 ,.!?\n]{1,10000}$/'); > >> > // it accepts > >> > testtesttesttesttesttest > > >> > // it refuses > >> > testtest > >> > testtest > >> > testtest > > >> Most likely, because of \r. > >> An obvious solution would be: > >> define('VALID_MESSAGE','/^[a-z0-9,.!?\s]{1,10000}$/i'); > > Please don't toppost. > > > it still says the message is invalid > > Not here it doesn't: > <?php > $variable = 'tasdtasd > asdasd > asdasd > asdasd'; > $valid = '/^[a-z0-9,.!?\s]{1,10000}$/'; > echo preg_match($valid, $variable) ? 'valid' : 'invalid'; > ?> > Outputs:valid > > If you made sure the right regex & variable arrived at your function, i'd > be interested in this output: > for($i = 0;$i < strlen($variable) ; $i++){ > echo $variable[$i].'='.ord($variable[$i])."\n";} > > -- > Rik Wasmus the output is t=116 e=101 s=115 t=116 t=116 e=101 s=115 t=116 t=116 e=101 s=115 t=116 t=116 e=101 s=115 t=116 \=92 r=114 \=92 n=110 t=116 e=101 s=115 t=116 t=116 e=101 s=115 t=116 \=92 r=114 \=92 n=110 t=116 e=101 s=115 t=116 t=116 e=101 s=115 t=116 |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On Jun 20, 4:54pm, Raistlin Majere <pedbe...@gmail.com> wrote:
> On Jun 20, 4:50pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote: > > > > > On Fri, 20 Jun 2008 21:43:05 +0200, Raistlin Majere <pedbe...@gmail.com> > > wrote: > > > > On Jun 20, 4:17pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote: > > >> On Fri, 20 Jun 2008 21:08:24 +0200, Raistlin Majere > > >> <pedbe...@gmail.com> > > >> wrote: > > > >> > define('VALID_MESSAGE', '/^[a-zA-Z0-9 ,.!?\n]{1,10000}$/'); > > >> > // it accepts > > >> > testtesttesttesttesttest > > > >> > // it refuses > > >> > testtest > > >> > testtest > > >> > testtest > > > >> Most likely, because of \r. > > >> An obvious solution would be: > > >> define('VALID_MESSAGE','/^[a-z0-9,.!?\s]{1,10000}$/i'); > > > Please don't toppost. > > > > it still says the message is invalid > > > Not here it doesn't: > > <?php > > $variable = 'tasdtasd > > asdasd > > asdasd > > asdasd'; > > $valid = '/^[a-z0-9,.!?\s]{1,10000}$/'; > > echo preg_match($valid, $variable) ? 'valid' : 'invalid'; > > ?> > > Outputs:valid > > > If you made sure the right regex & variable arrived at your function, i'd > > be interested in this output: > > for($i = 0;$i < strlen($variable) ; $i++){ > > echo $variable[$i].'='.ord($variable[$i])."\n";} > > > -- > > Rik Wasmus > > the output is > > t=116 e=101 s=115 t=116 t=116 e=101 s=115 t=116 t=116 e=101 s=115 > t=116 t=116 e=101 s=115 t=116 \=92 r=114 \=92 n=110 t=116 e=101 s=115 > t=116 t=116 e=101 s=115 t=116 \=92 r=114 \=92 n=110 t=116 e=101 s=115 > t=116 t=116 e=101 s=115 t=116 it really looks like the problem is not with the regexp, but with the code but what is the problem??? |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
On Jun 20, 4:50pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote:
> On Fri, 20 Jun 2008 21:43:05 +0200, Raistlin Majere <pedbe...@gmail.com> > wrote: > > > > > On Jun 20, 4:17pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote: > >> On Fri, 20 Jun 2008 21:08:24 +0200, Raistlin Majere > >> <pedbe...@gmail.com> > >> wrote: > > >> > define('VALID_MESSAGE', '/^[a-zA-Z0-9 ,.!?\n]{1,10000}$/'); > >> > // it accepts > >> > testtesttesttesttesttest > > >> > // it refuses > >> > testtest > >> > testtest > >> > testtest > > >> Most likely, because of \r. > >> An obvious solution would be: > >> define('VALID_MESSAGE','/^[a-z0-9,.!?\s]{1,10000}$/i'); > > Please don't toppost. > > > it still says the message is invalid > > Not here it doesn't: > <?php > $variable = 'tasdtasd > asdasd > asdasd > asdasd'; > $valid = '/^[a-z0-9,.!?\s]{1,10000}$/'; > echo preg_match($valid, $variable) ? 'valid' : 'invalid'; > ?> > Outputs:valid > > If you made sure the right regex & variable arrived at your function, i'd > be interested in this output: > for($i = 0;$i < strlen($variable) ; $i++){ > echo $variable[$i].'='.ord($variable[$i])."\n";} > > -- > Rik Wasmus It really looks like the problem is not with the regexp, but with the rest of the code, but what is the problem??? |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
On Fri, 20 Jun 2008 21:54:57 +0200, Raistlin Majere <pedbessa@gmail.com>
wrote: > On Jun 20, 4:50pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote: >> On Fri, 20 Jun 2008 21:43:05 +0200, Raistlin Majere >> <pedbe...@gmail.com> >> wrote: >> >> >> >> > On Jun 20, 4:17pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote: >> >> On Fri, 20 Jun 2008 21:08:24 +0200, Raistlin Majere >> >> <pedbe...@gmail.com> >> >> wrote: >> >> >> > define('VALID_MESSAGE', '/^[a-zA-Z0-9 ,.!?\n]{1,10000}$/'); >> >> > // it accepts >> >> > testtesttesttesttesttest >> >> >> > // it refuses >> >> > testtest >> >> > testtest >> >> > testtest >> >> >> Most likely, because of \r. >> >> An obvious solution would be: >> >> define('VALID_MESSAGE','/^[a-z0-9,.!?\s]{1,10000}$/i'); >> >> Please don't toppost. >> >> > it still says the message is invalid >> >> Not here it doesn't: >> <?php >> $variable = 'tasdtasd >> asdasd >> asdasd >> asdasd'; >> $valid = '/^[a-z0-9,.!?\s]{1,10000}$/'; >> echo preg_match($valid, $variable) ? 'valid' : 'invalid'; >> ?> >> Outputs:valid >> >> If you made sure the right regex & variable arrived at your function, >> i'd >> be interested in this output: >> for($i = 0;$i < strlen($variable) ; $i++){ >> echo $variable[$i].'='.ord($variable[$i])."\n";} > the output is > > ... \=92... '\' is not valid, some code is escaping the \r & \n characters in your $variable when you don't expect it. '\n' != "\n" Not something addslashes() or magic_quotes would do, so the usual suspects for incorrect escaping do not apply. Perhaps a premature mysql_(real_)escape_string? Trace it back I'd say, examine the route your $variable goes, and aat what point the newline character stops being a newline character. -- Rik Wasmus ....spamrun finished |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
On Jun 20, 5:14pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote:
> On Fri, 20 Jun 2008 21:54:57 +0200, Raistlin Majere <pedbe...@gmail.com> > wrote: > > > > > On Jun 20, 4:50pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote: > >> On Fri, 20 Jun 2008 21:43:05 +0200, Raistlin Majere > >> <pedbe...@gmail.com> > >> wrote: > > >> > On Jun 20, 4:17pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote: > >> >> On Fri, 20 Jun 2008 21:08:24 +0200, Raistlin Majere > >> >> <pedbe...@gmail.com> > >> >> wrote: > > >> >> > define('VALID_MESSAGE', '/^[a-zA-Z0-9 ,.!?\n]{1,10000}$/'); > >> >> > // it accepts > >> >> > testtesttesttesttesttest > > >> >> > // it refuses > >> >> > testtest > >> >> > testtest > >> >> > testtest > > >> >> Most likely, because of \r. > >> >> An obvious solution would be: > >> >> define('VALID_MESSAGE','/^[a-z0-9,.!?\s]{1,10000}$/i'); > > >> Please don't toppost. > > >> > it still says the message is invalid > > >> Not here it doesn't: > >> <?php > >> $variable = 'tasdtasd > >> asdasd > >> asdasd > >> asdasd'; > >> $valid = '/^[a-z0-9,.!?\s]{1,10000}$/'; > >> echo preg_match($valid, $variable) ? 'valid' : 'invalid'; > >> ?> > >> Outputs:valid > > >> If you made sure the right regex & variable arrived at your function, > >> i'd > >> be interested in this output: > >> for($i = 0;$i < strlen($variable) ; $i++){ > >> echo $variable[$i].'='.ord($variable[$i])."\n";} > > the output is > > > ... \=92... > > '\' is not valid, some code is escaping the \r & \n characters in your > $variable when you don't expect it. '\n' != "\n" Not something > addslashes() or magic_quotes would do, so the usual suspects for incorrect > escaping do not apply. Perhaps a premature mysql_(real_)escape_string? > Trace it back I'd say, examine the route your $variable goes, and aat what > point the newline character stops being a newline character. > -- > Rik Wasmus > ...spamrun finished IT WORKED!!! It was a premature mysql_real_escape_string indeed! Thank you very much! |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
On Jun 20, 10:08pm, Raistlin Majere <pedbe...@gmail.com> wrote:
> // there is > > define('VALID_MESSAGE', '/^[a-zA-Z0-9 ,.!?\n]{1,10000}$/'); > > // there is > > function validate($variable, $name, $valid, $name2, $inornot) > > // there is > > if (!preg_match($valid, $variable)) { > $_SESSION["trying"]="The ".$name." is invalid!"; > return false; > > } > > // it accepts > > testtesttesttesttesttest > > // it refuses > > testtest > testtest > testtest > > Why? YOU NEED TO ESCAPE SPECIAL CHARACTERS LIKE DOTS . AND DASHES - \. \- AND ALSO \$ \^ \[ \] \{ ETC. THEY GO ON IF YOU ARE SEARCHING FIR THEM |
|
![]() |
| Outils de la discussion | |
|
|