SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2002
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cookie script problem

    hmm below is the code from a cookie file for a poll..it seems to not be working because im on 56k and when i redial in i can still vote...is there something wrong with it?


    PHP Code:
    <?php
    /**
     * ----------------------------------------------
     * this code is optional
     * Important! You have to include it 
     * before your html code
     * ----------------------------------------------
     */

    global $HTTP_GET_VARS$HTTP_POST_VARS;
    $cookie_expire 96// hours

    $action = (isset($HTTP_GET_VARS['action'])) ? $HTTP_GET_VARS['action'] : '';
    $action = (isset($HTTP_POST_VARS['action'])) ? $HTTP_POST_VARS['action'] : $action;
    $poll_ident = (isset($HTTP_GET_VARS['poll_ident'])) ? $HTTP_GET_VARS['poll_ident'] : '';
    $poll_ident = (isset($HTTP_POST_VARS['poll_ident'])) ? $HTTP_POST_VARS['poll_ident'] : $poll_ident;

    if (
    $action=="vote" && (isset($HTTP_POST_VARS['option_id']) || isset($HTTP_GET_VARS['option_id']))) {
        
    $cookie_name "AdvancedPoll".$poll_ident;
        if (!isset(
    $HTTP_COOKIE_VARS[$cookie_name])) {
            
    $endtime time()+3600*$cookie_expire;
            
    setcookie($cookie_name"1"$endtime);
        }
    }

    ?>
    Last edited by freakysid; Nov 27, 2002 at 03:42.

  2. #2
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow, all that conditional logic is pretty heavy going. I bet the logic could be simplified. My first guess is that the branch of the program that has the call to setcookie() is never entered.

    The best thing to do to try and pin point your bug is to place some debugging code in your script. The good old tried and true method is to print out messages that help you work out what is going on when you script executes. For example:
    PHP Code:
    <?php
    global $HTTP_GET_VARS$HTTP_POST_VARS;
    $cookie_expire 96// hours

    $action = (isset($HTTP_GET_VARS['action'])) ? $HTTP_GET_VARS['action'] : '';
    $action = (isset($HTTP_POST_VARS['action'])) ? $HTTP_POST_VARS['action'] : $action;
    $poll_ident = (isset($HTTP_GET_VARS['poll_ident'])) ? $HTTP_GET_VARS['poll_ident'] : '';
    $poll_ident = (isset($HTTP_POST_VARS['poll_ident'])) ? $HTTP_POST_VARS['poll_ident'] : $poll_ident;

    if (
    $action=="vote" && (isset($HTTP_POST_VARS['option_id']) || isset($HTTP_GET_VARS['option_id']))) {
        
    $cookie_name "AdvancedPoll".$poll_ident;
        if (!isset(
    $HTTP_COOKIE_VARS[$cookie_name])) {
            
    $endtime time()+3600*$cookie_expire;
            
    //setcookie($cookie_name, "1", $endtime);
        
    }
    }

    ?>
    Are you aware that || has higher precedence than && ? This mean that the || will be evaluated first and then the &&


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •