좋아, 한 가지 방법은 메시지가 채팅 파일에 추가되기 전에 확인하는 것입니다. PHP로이를 수행하는 쉬운 방법은 반복되는 값을위한 카운터를 저장할 PHP 세션을 사용하는 것입니다. PHP 세션이 필요
"채팅 포스트"를위한
1. 세션 기능 : 나는 당신의 사이트의 구조를 알 수 없기 때문에, 나는 당신에게이 작업을 수행하는 방법에 대한 기본 지침을주지 어디에서든 시작할 수 있습니다. 이것은 간단하게 할 수 있습니다. 이 마지막 링크
session_start();
if(!isset($_SESSION['latest_link'])){ //isset() checks whether or not the variable exists
$_SESSION['latest_link'] = "";
}
if(!isset($_SESSION['duplicate_count'])){
$_SESSION['duplicate_count'] = 0;
}
if($_SESSION['latest_link'] == trim(strtolower($link))){ //where $link is the new link being posted. trim() removes unneeded whitespace and strtolower() makes everything lowercase. This way, the poster can't fool the system through capitalization or extra spaces
}
에게 일치하는 경우
session_start();
2는 새로운 링크는
session_start();
if(!isset($_SESSION['latest_link'])){ //isset() checks whether or not the variable exists
$_SESSION['latest_link'] = "";
}
if(!isset($_SESSION['duplicate_count'])){
$_SESSION['duplicate_count'] = 0;
}
3. 존재하지 않는 경우 두 개의 세션 변수를 만들기 확인
5. 링크가 중복 된 경우 duplicate_count
에 하나 추가 .
session_start();
if(!isset($_SESSION['latest_link'])){ //isset() checks whether or not the variable exists
$_SESSION['latest_link'] = "";
}
if(!isset($_SESSION['duplicate_count'])){
$_SESSION['duplicate_count'] = 0;
}
if($_SESSION['latest_link'] == trim(strtolower($link))){ //where $link is the new link being posted. trim() removes unneeded whitespace and strtolower() makes everything lowercase. This way, the poster can't fool the system through capitalization or extra spaces
$_SESSION['duplicate_count']++; //add one to duplicate_count
}
6.이 다르고,
단순히 함께 할 카운터를 재설정하면 duplicate_count
보다 큰 2
session_start();
if(!isset($_SESSION['latest_link'])){ //isset() checks whether or not the variable exists
$_SESSION['latest_link'] = "";
}
if(!isset($_SESSION['duplicate_count'])){
$_SESSION['duplicate_count'] = 0;
}
if($_SESSION['latest_link'] == trim(strtolower($link))){ //where $link is the new link being posted. trim() removes unneeded whitespace and strtolower() makes everything lowercase. This way, the poster can't fool the system through capitalization or extra spaces
$_SESSION['duplicate_count']++; //add one to duplicate_count
}
if($_SESSION['duplicate_count'] > 2){
//user has posted same link more than 2 times. Action should be taken.
}
7. 로그인 사용자의 최신 링크 인 경우
session_start();
if(!isset($_SESSION['latest_link'])){ //isset() checks whether or not the variable exists
$_SESSION['latest_link'] = "";
}
if(!isset($_SESSION['duplicate_count'])){
$_SESSION['duplicate_count'] = 0;
}
if($_SESSION['latest_link'] == trim(strtolower($link))){ //where $link is the new link being posted. trim() removes unneeded whitespace and strtolower() makes everything lowercase. This way, the poster can't fool the system through capitalization or extra spaces
$_SESSION['duplicate_count']++; //add one to duplicate_count
}else{
$_SESSION['latest_link'] = trim(strtolower($link));
$_SESSION['duplicate_count'] = 0;
}
if($_SESSION['duplicate_count'] > 2){
//user has posted same link more than 2 times. Action should be taken.
}
당신은 또한 session hijacking
을 막기 위해 세션 보안을 고려해야합니다.하지만 스택 오버플로에 대한 많은 답을 찾을 수있는 또 다른 주제입니다. 이 게시물은 좋은 포인터를 가지고 있습니다 : PHP Session Security
무엇이 문제입니까? 너 뭐 해봤 니? –
PHP 세션을 사용하여 마지막 세 개의 메시지를 추적하면 쉽게이를 수행 할 수 있습니다. 그러나, 나는 컨텍스트와 당신이 지금까지 시도한 것을 이해하는 것 같지 않습니다. –
@PatrickJamesMcDougle, 나는 코딩에 멍청한 사람이긴하지만'count (explode' 문제는 내가 모든 사용자가 아니라 동일한 사용자 $ name에 의해 정확한 채팅 단어 또는 링크를 계산하는 방법을 알지 못한다.) – GuestofHonor