PHP를 사용하여 온라인 채팅방을 만들고 채팅을 새로 고침 버튼이 있습니다. 나중에 버튼이 숨겨 지지만 자바 스크립트가 자동으로 매초마다 클릭하지만 매번 약간의 문제가 있습니다. 클릭하면 텍스트 상자가 다시 설정되므로 사용자는 메시지를 다시 시작해야합니다. 다음은 teamhaxor.netau.net/Stuff/Chat/chat.php 데모입니다.PHP 텍스트 상자 재설정
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="submit" name="refresh" id="update">
</form>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="text" name="text" id="text">
<input type="submit" name="send">
</form>
<?php
if(isset($_POST['refresh'])) /* i.e. the PHP code is executed only when someone presses Submit button in the below given HTML Form */
{
if ($file = fopen("log.txt", "r")) {
while(!feof($file)) {
$line = fgets($file);
echo $line . "<br>";
}
fclose($file);
}
}
if(isset($_POST['send'])) /* i.e. the PHP code is executed only when someone presses Submit button in the below given HTML Form */
{
$text = $_POST['text'];
$myfile = fopen("log.txt", "a+") or die("Unable to open file!");
fwrite($myfile, "\n" . $text);
fclose($myfile);
}
?>
<script>
setInterval(function(){
element = document.getElementById('update');
element.click()
}, 1000);
</script>
가 어떻게 그렇지 않은 사용자가 입력 한 텍스트를 다시 만들 수 있습니다
이
코드인가? 미리 감사드립니다.
왜 제출 버튼을 누르기 위해 필요합니까? 타이머에 넣고 자동으로 실행합니다. – Machavity
PHP에서 멈춤이있는 루프를 만들려고 할 때 작동하지 않았기 때문에 모든 것을 변경하려고 시도했지만 여전히 작동하지 않았습니다. 만약 당신이 그것을 알아 냈어 루프에 대한 몇 가지 코드를 보내주십시오. 감사. – Woowing
나는 클라이언트 측과 서버 측 사이의 차이점을 얻지 못할 것이라고 생각한다. – Machavity