1cfd3bbb56
Topic_CSS/Topic_HTML/Topic_JavaScript/Topic_Prompt/Topic_Comfyui 등 기존 카테고리 폴더를 정리하고, Topic_Graphic/Dev 등 신규 산출물과 Topics 내부 세션/메모리 기록을 동기화.
4.0 KiB
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 |
|
B | 0.87 | 2026-07-04 | 2026-07-04 |
|
|
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)
onclickevent — triggers on radio button selection (vs.onkeyup/onchangein earlier chapters). [S1]- Same AJAX skeleton —
XMLHttpRequest+onreadystatechange, now sending avoteparameter instead of a search string. [S1] - File-based vote storage —
poll_result.txtstores counts as"yesCount||noCount", parsed viaexplode("||", $content[0]). [S1] - Read-modify-write cycle —
file()reads current counts, increments the relevant one, thenfopen()+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)
- 상위/루트: PHP Tutorial
- 관련 개념: PHP AJAX Live Search, PHP Files Write, PHP File Create
- 참조 맥락: AJAX 섹션이자 PHP 튜토리얼 전체의 마지막 챕터 — 파일 기반 데이터 저장을 실전 활용으로 마무리.
📚 출처 (Sources)
- [S1] W3Schools — PHP - AJAX Poll — https://www.w3schools.com/php/php_ajax_poll.asp
📝 변경 이력 (Change history)
- 2026-07-04: Initial draft synthesized from the W3Schools "PHP - AJAX Poll" page (Astra wiki-curation, P-Reinforce v3.1 format).