---
id: php-ajax-poll
title: "PHP AJAX Poll"
category: "Programming_Language"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["PHP AJAX ν¬ν"]
duplicate_of: ""
source_trust_level: "B"
confidence_score: 0.87
created_at: 2026-07-04
updated_at: 2026-07-04
review_reason: ""
merge_history: []
tags: ["php", "programming", "w3schools", "ajax", "file-handling"]
raw_sources: ["https://www.w3schools.com/php/php_ajax_poll.asp"]
applied_in: []
github_commit: ""
---
# [[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 skeleton** β `XMLHttpRequest` + `onreadystatechange`, now sending a `vote` parameter instead of a search string. [S1]
- **File-based vote storage** β `poll_result.txt` stores counts as `"yesCount||noCount"`, parsed via `explode("||", $content[0])`. [S1]
- **Read-modify-write cycle** β `file()` 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 `
` 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: `
%`. [S1]
## βοΈ λͺ¨μ λ° μ
λ°μ΄νΈ (Contradictions & updates)
- **νμΌ μ°κΈ° κΆν κ²½κ³ **: poll_result.txtμ λν μ°κΈ° κΆνμ μΉ μλ²(PHP)μλ§ λΆμ¬ν΄μΌ νλ©° λͺ¨λ μ¬μ©μμκ² μ΄μ΄μ£Όλ©΄ μ λλ€λ μ μ΄ λͺ
μμ μΌλ‘ κ²½κ³ λ¨. [S1]
## π οΈ μ μ© μ¬λ‘ (Applied in summary)
νμ¬ λ°κ²¬λ μ€μ μ μ© μ¬λ‘κ° μμ΅λλ€ β ν
μ€νΈ νμΌλ‘ ν¬νμλ₯Ό μ μ₯νκ³ κ·Έλν½ λ§λλ‘ λΉμ¨μ νμνλ κ²μ΄ νμΌ κΈ°λ° λ°μ΄ν° μμνμ λν μ€μ μ¬λ‘λ€. [S1]
## π» μ½λ ν¨ν΄ (Code patterns)
Read-modify-write vote counting in a text file (PHP):
```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).