ENGL 8122  ※  User-Experience Research & Writitng

Thumb Voting System

Thumb Voting System

14 11

Most of this script was written by ChatGPT's code interpreter. My request was, "Please write a php thumb up or thumb down script that keeps a running record of users' assessments in a file on the server. You can use html entities for the thumbs." I tinkered with the layout. The script works. But it is simplistic. A user could skew the tally by hitting up or down repeatedly. Just refreshing the page adds another vote to the previous tally.

Were I to use this script, I don't think I would show the tally. I feel like showing it might prejudice the assessments. How might one test for that? I would also want a clearer sense of what a given thumb up or thumb down might mean, what motivated the assessment and how adamant a given user was. It's a binary distinction and so it requires a very specific setting to provide useful data. Live or die, keep or delete, essentially. A star system might be more helpful in a wider range of settings. Or an emoticon evaluation with happy, neutral, and sad faces. At least with that a person could record their abstention or indifference.

If you want this script, you need to have access to a file server that can run php scripts and you would need to use the .php extension for the file using this code.

<?php
// File to store the count of thumbs up and thumbs down
$filename = 'votes.txt';

// Check if the file exists, if not create it with initial values
if (!file_exists($filename)) {
    file_put_contents($filename, json_encode(['up' => 0, 'down' => 0]));
}

// Read the current counts
$votes = json_decode(file_get_contents($filename), true);

// Check if a vote has been submitted
if (isset($_POST['vote'])) {
    if ($_POST['vote'] === 'up') {
        $votes['up']++;
    } elseif ($_POST['vote'] === 'down') {
        $votes['down']++;
    }
    // Save the updated counts
    file_put_contents($filename, json_encode($votes));
}

// HTML and PHP to display the voting buttons and current counts

print "Thumbs Up: <?= $votes['up'] ?>  Thumbs Down: <?= $votes['down'] ?> ";

?>