Files
2nd/10_Wiki/Topic_Programming/Topic_PHP/PHP_AJAX_Poll.md
T
Antigravity Agent e9cbf23ab5 docs(10_Wiki): Dev 폴더 누락분 반영 — Topic_Programming으로 통합
이전 재구성 작업에서 Dev/ 폴더가 누락되었던 것을 반영.

- Dev/Topic_Programming(중첩 폴더, 78개)은 Dev 자체 최상위 폴더들
  (Architecture/Conventions/Engineering_Intelligence 등)과 완전 중복이라 제거.
- Dev 최상위 엔지니어링 지식 폴더(Architecture/Conventions/Engineering_Intelligence/
  Failure_Library/Generalized_Principles/Language/Pattern_Catalog/Platform_Guides/
  Subsystems, 77개)는 이미 Topic_Programming/Topic_Programming에 더 최신 버전이
  존재해 중복 제거(고유 콘텐츠 1개는 예외 처리하여 이동 보존).
- Dev의 W3Schools 언어 튜토리얼 폴더(Topic_C/CPP/CSS/CSharp/HOWTO/HTML/Java/
  JavaScript/PHP/Python/SQL/W3CSS, 1201개)는 전부 Topic_Programming 하위로 이동.
- 에이전트 운영 상태(.astra/docs)는 그대로 유지, 콘텐츠 폴더만 정리.
- Topic_Programming 최종 문서 수: 2784 → 3985.
2026-07-05 00:39:13 +09:00

4.0 KiB

id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
id title category status verification_status canonical_id aliases duplicate_of source_trust_level confidence_score created_at updated_at review_reason merge_history tags raw_sources applied_in github_commit
php-ajax-poll PHP AJAX Poll Programming_Language draft conceptual
PHP AJAX 투표
B 0.87 2026-07-04 2026-07-04
php
programming
w3schools
ajax
file-handling
https://www.w3schools.com/php/php_ajax_poll.asp

PHP AJAX Poll

🎯 한 줄 통찰 (One-line insight)

This poll persists its vote counts in a PLAIN TEXT FILE (poll_result.txt, format "0||0"), not a database — and the source explicitly warns to grant the WEB SERVER write access to that file, but NOT everyone, framing file permissions as the specific security concern for this simpler persistence approach. [S1]

🧠 핵심 개념 (Core concepts)

  • onclick event — triggers on radio button selection (vs. onkeyup/onchange in earlier chapters). [S1]
  • Same AJAX skeletonXMLHttpRequest + onreadystatechange, now sending a vote parameter instead of a search string. [S1]
  • File-based vote storagepoll_result.txt stores counts as "yesCount||noCount", parsed via explode("||", $content[0]). [S1]
  • Read-modify-write cyclefile() reads current counts, increments the relevant one, then fopen()+fputs()+fclose() overwrites the file with updated counts. [S1]
  • Graphical percentage bars — computed inline with round($yes/($no+$yes),2) and rendered as a proportionally-sized <img> width. [S1]
  • File permission warning — only the web server (PHP process) should have write access to poll_result.txt, not all users. [S1]

📖 세부 내용 (Details)

  • Read-modify-write vote logic: $vote = $_REQUEST['vote']; $content = file($filename); $array = explode("||", $content[0]); $yes = $array[0]; $no = $array[1]; if ($vote == 0) { $yes = $yes + 1; } if ($vote == 1) { $no = $no + 1; } $insertvote = $yes."||".$no; $fp = fopen($filename,"w"); fputs($fp,$insertvote); fclose($fp);. [S1]
  • Percentage bar rendering: <img src="poll.gif" width='<?php echo(100*round($yes/($no+$yes),2)); ?>' height='20'> <?php echo(100*round($yes/($no+$yes),2)); ?>%. [S1]

⚖️ 모순 및 업데이트 (Contradictions & updates)

  • 파일 쓰기 권한 경고: poll_result.txt에 대한 쓰기 권한은 웹 서버(PHP)에만 부여해야 하며 모든 사용자에게 열어주면 안 된다는 점이 명시적으로 경고됨. [S1]

🛠️ 적용 사례 (Applied in summary)

현재 발견된 실제 적용 사례가 없습니다 — 텍스트 파일로 투표수를 저장하고 그래픽 막대로 비율을 표시하는 것이 파일 기반 데이터 영속화의 대표 실전 사례다. [S1]

💻 코드 패턴 (Code patterns)

Read-modify-write vote counting in a text file (PHP):

$vote = $_REQUEST['vote'];
$content = file("poll_result.txt");
$array = explode("||", $content[0]);
$yes = $array[0]; $no = $array[1];
if ($vote == 0) { $yes = $yes + 1; }
if ($vote == 1) { $no = $no + 1; }
$fp = fopen("poll_result.txt", "w");
fputs($fp, $yes."||".$no);
fclose($fp);

검증 상태 및 신뢰도

  • 상태: draft
  • 검증 단계: conceptual
  • 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
  • 신뢰 점수: 0.87
  • 중복 검사 결과: 신규 생성 (New discovery)

🔗 지식 그래프 (Knowledge Graph)

📚 출처 (Sources)

📝 변경 이력 (Change history)

  • 2026-07-04: Initial draft synthesized from the W3Schools "PHP - AJAX Poll" page (Astra wiki-curation, P-Reinforce v3.1 format).