System / reddit in php

I am looking for examples of how to implement the StackOverflow / reddit voting system in php.

Mostly I want an up and down arrow. Are there any good examples there?

+5
source share
2 answers

There are many scenarios out there , but it is not too difficult to do it yourself.

I used jQuery (for AJAX processing) and a small PHP script before. For example, some pseudo code:

// Some checking for recent votes from this user is appropriate here if (isset($_POST['voteType'], $_POST['postId']) && $user->loggedIn) { // insert vote into database if not already inserted echo json_encode(array('error' => false)); } else { // bad request/hack attempt echo json_encode(array('error' => true, 'message' => 'Bad parameters sent')); } 

and then some jQuery:

 $('#upVote').click(function() { $.post('vote.php', {voteType: 'up', postId: 42}, 'updateIcon(data, textStatus)', 'json'); }); function updateIcon(data, textStatus) { // If error = false highlight the upvote icon // else show the error message returned } 

jQuery.post

+6
source
0
source

Source: https://habr.com/ru/post/915076/


All Articles