Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7166519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:25:37+00:00 2026-05-28T14:25:37+00:00

I am really suffering here trying to get this ajax call to work, sorry

  • 0

I am really suffering here trying to get this ajax call to work, sorry for the massiveness of this question.

The user clicks a button, this initiated an ajax call to add a vote to the database. Here is the file called “addvote.php”:

<?php
session_start();


/* COOKIECHECK START */

setcookie('test', 1, time()+3600);
if(!isset($_GET['cookies'])){
    header("Location:/thought/addvote.php?cookies=true&id=".$_GET['id']."&ans=".$_GET['ans']);
}

if(count($_COOKIE) > 0){
    $cookies=1;
} else {
    $cookies=0;
}

/* COOKIECHECK END */



if($cookies==1) {

    $id=$_GET["id"];
    $vId="v".$id;

if (((isset($_SESSION[$vId]) && ((time() - $_SESSION[$vId]) > 180))) || (!isset($_SESSION[$vId]))) {
    // last vote was more than 3 minutes ago
    $_SESSION[$vId] = time(); // update/create vote time stamp

        //ADD VOTE TO DATABASE

    }
    else {
    echo "You've voted on this already";
    }
}
else {
    echo "Please enable cookies to make your vote count";
}


?>

What is supposed to happen: The user is checked to see if they have cookies enabled. If so, they are allowed to add a vote, if not tell them to enable cookies. If they have cookies enabled, and they havn’t voted already – add a vote, if they have voted already, tell them.

What actually happens: A user who hasn’t voted yet clicks the button, this initiates the ajax call and the vote is successfully added, no message is sent to the user. They then move onto another question and click the vote button, “addvote.php” is initiated, but this time it returns “You’ve voted on this already” AND adds a vote! This makes me thing that the page call is running twice, first it adds the vote, then it tries again (and returns the error).

Maybe it has something to do with the header()??

Every question then returns this same message and adds a vote – unless I wait a while and then it works on the first question and the same thing happens again.

Point of note is:
The GET variables are passed along with the header so that I know which question they’re talking about and whether they clicked no or yes.

Again, apologies, this question is a horrible one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:25:38+00:00Added an answer on May 28, 2026 at 2:25 pm

    This will not prevent cheating with voting anyway. To test if user has cookies enabled, you can, for example, set cookie using JavaScript on voting page and check it in PHP. But, obviously, if someone wants to cheat, he or she will remove your cookies manually.

    Furthemore, you need to add exit after header() call to make your code work:

    setcookie('test', 1, time()+3600);
    if(!isset($_GET['cookies'])){
        header("Location:/thought/addvote.php?cookies=true&id=".$_GET['id']."&ans=".$_GET['ans']);
        exit;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Really stupid question, sorry, but I can't find it on google (I'm sure it's
Really quick jQuery question... I have this function: $(document).ready(function() { $('a#show1').click(function() { $('.item1').toggle(1000); return
Really simple question: From within GWT I want to forward the user away from
Hey, well I don't really know how to describe this but here's my current
Really basic question I'm sure for the normal Mac user but; I'm a very
I have the feeling this has a really simple solution and I'm just suffering
Really simple question - how do I do a search to find all records
Really stuck on trying to write code to unzip a file or directory on
Really my question has more to do with the server-side scrubbing of html that's
Really basic question I'm sure for some of you Java heads out there. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.