PHP 자체가 정규식을 확인할 것이라고 생각합니다.
이
// check for input, and set max size of input
if(@!empty($_POST['regex'])
&& @!empty($_POST['text'])
&& strlen($_POST['regex'])<1000
&& strlen($_POST['text'])<2000
){
// set script timeout in case something goes wrong (SAFE MODE must be OFF)
$old_time=ini_get('max_execution_time');
if(!set_time_limit(1)) die('SAFE MODE MUST BE OFF'); // 1 sec is more then enough
// trim input, it's up to you to do more checks
$regex=trim($_POST['regex']);
// don't trim the text, it can be needed
$input=$_POST['text'];
// escape slashes
$regex=preg_replace('/([\\/]+)?//', '\/', $regex);
// go for the regex
if([email protected]_match('/'.$regex.'/', $input, $matches)){
// regex was tested, show results
echo 'Matches: '.$matched.'<br />';
if($matched>0){
echo 'matches: <br />';
foreach($matches as $i => $match){
echo $i.' = '.$match.'<br />';
}
}
}
// set back original execution time
set_time_limit($old_time);
}
가 어쨌든, 가 NEVER EVER 사용자가 제출 문자열()로 평가 사용 여기에 내가 만든 샘플 스크립트입니다.
또한 최소한의 간단한 위생 처리를 수행 할 수 있지만 그게 당신에게 달린 것입니다. ;)
왜 JS를 사용하지 않습니까? 이렇게하면 클라이언트 측에서 실행되므로 아무 것도 위생 할 필요가 없습니다. – Daan
사용자 제공 샘플 텍스트에서 정규식을 평가하는 것 외에도 정규식을 서버에있는 "secret"문자열로 평가해야한다고 덧붙여 야합니다. 사용자가 문자열이 무엇인지 알지 못해 JS에서 그렇게하는 방법을 모르겠습니다. –