SitePoint Sponsor

User Tag List

Page 1 of 3 123 LastLast
Results 1 to 25 of 55
  1. #1
    Crazy Webmaster Cr0CX's Avatar
    Join Date
    Dec 2003
    Location
    WWW
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    what is it with this code?!!?!

    Quote Originally Posted by PHP Code
    <?PHP
    include("config.php");
    $ip = $REMOTE_ADDR;
    $id = $_GET['id'];
    $click = mysql_fetch_array(mysql_query("select * from clicks where id=$id"));

    if ($click[ip] == $ip) {
    print "<font face=arial size=2>Sorry you can only click once a day on each link.</font>";
    exit;
    }
    $givemoney = rand(1, 1500);
    mysql_query("insert into clicks (ip, id) values('$ip','$id')") or die("Could not add click.");
    mysql_query("update players set credits=credits+$givemoney where id=$id");
    $userstat = mysql_fetch_array(mysql_query("select * from players where id=$id"));

    print "<font face=arial size=2>$userstat[user] just got $givemoney credits.</font>";
    exit;
    ?>
    whats the problem here? it gives any one click as much as he wants, and its shuld not..
    Run a site? over 1,000 uniques a day? PM me for link exchange.

  2. #2
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is the click['ip'] and $ip what you expect them to be?
    Echo them out and see.

    -Helge

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    Leuven, Belgium
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you could try instead:
    $ip = $_SERVER['REMOTE_ADDR'];
    I'm sure others will have a few comments on this code security-wise, the queries could also be slightly improved.

  4. #4
    Employed Again Viflux's Avatar
    Join Date
    May 2003
    Location
    London, On.
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried using if/else syntax to control the flow, rather than using exit to break out of your conditional?

    That would be the first thing I'd try.

    As pointed out above, you'll want to perform some kind of validation on both the $ip and the $id to see A) if they are valid, and B) if they are what you expect.

    Also, your use of exit in some places and die in others is odd. They are the same language construct, so for better structure and code, you should choose one and use it exclusively.

  5. #5
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    I take it that
    PHP Code:
    $ip $REMOTE_ADDR
    has been assigned a variable earlier in the script or did you mean
    PHP Code:
    $ip $_SERVER['REMOTE_ADDR']; 
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  6. #6
    Crazy Webmaster Cr0CX's Avatar
    Join Date
    Dec 2003
    Location
    WWW
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    still wont work... now im trying this:
    Quote Originally Posted by CODE
    <?PHP
    include("config.php");
    $ip = $_SERVER['REMOTE_ADDR'];
    $id = $_GET['id'];
    $clicks = mysql_fetch_array(mysql_query("select * from clicks where id=$id and ip='$ip'"));
    if (empty ($clicks)) {
    $givemoney = rand(1, 1500);
    mysql_query("insert into clicks (ip, id) values('$ip','$id')") or die("Could not add click.");
    mysql_query("update players set credits=credits+$givemoney where id=$id");
    $userstat = mysql_fetch_array(mysql_query("select * from players where id=$id"));
    print "<font face=arial size=2>$userstat[user] just got $givemoney credits.</font>";
    exit;
    }
    ?>
    whats wrong, lets any one click as much as he likes
    Run a site? over 1,000 uniques a day? PM me for link exchange.

  7. #7
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't tell but I gave you a debugging advice earlier. Did you try it?
    What is echoed out from this code?
    PHP Code:
    <?php
    include("config.php");

    $ip $_SERVER['REMOTE_ADDR'];
    $id $_GET['id'];

    $sql "select * from clicks where id=$id and ip='$ip'";
    $result mysql_query($sql) or die(mysql_error());
    $clicks mysql_fetch_array($result) or die(mysql_error());

    echo 
    "<p>ip: $ip<br />";
    echo 
    "id: $id<br />";
    echo 
    "sql: $sql<br />";
    echo 
    "clicks: $clicks</p>";

    if (empty (
    $clicks)) {
        
    $givemoney rand(11500);
        
    mysql_query("insert into clicks (ip, id) values('$ip','$id')") or die(mysql_error());
        
    mysql_query("update players set credits=credits+$givemoney where id=$id") or die(mysql_error());
        
    $userstat mysql_fetch_array(mysql_query("select * from players where id=$id"));
        print 
    "<font face=arial size=2>$userstat[user] just got $givemoney credits.</font>";
        exit;
    }
    ?>
    -Helge

  8. #8
    Crazy Webmaster Cr0CX's Avatar
    Join Date
    Dec 2003
    Location
    WWW
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Parse error: parse error, unexpected T_VARIABLE in /home/hiphop/public_html/wargame/click2.php on line 8
    Run a site? over 1,000 uniques a day? PM me for link exchange.

  9. #9
    Employed Again Viflux's Avatar
    Join Date
    May 2003
    Location
    London, On.
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sure your information is being INSERT'ed properly?

    Take a look from the command line (or phpmysql if that's what floats your boat).

  10. #10
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cr0CX
    Parse error: parse error, unexpected T_VARIABLE in /home/hiphop/public_html/wargame/click2.php on line 8
    Ooops, updated the code now. Forgot a ;

  11. #11
    Employed Again Viflux's Avatar
    Join Date
    May 2003
    Location
    London, On.
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by spikeZ
    I take it that
    PHP Code:
    $ip $REMOTE_ADDR
    has been assigned a variable earlier in the script or did you mean
    PHP Code:
    $ip $_SERVER['REMOTE_ADDR']; 
    Off Topic:


    I believe that older versions of PHP registered certain globals like this, meaning REMOTE_ADDR would be available. Same with $PHP_SELF.

    Could be mistaken though.

  12. #12
    Crazy Webmaster Cr0CX's Avatar
    Join Date
    Dec 2003
    Location
    WWW
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    now its not showing any thing... can any one helpp me re-code the whole thing? by ICQ, or something?
    Run a site? over 1,000 uniques a day? PM me for link exchange.

  13. #13
    Crazy Webmaster Cr0CX's Avatar
    Join Date
    Dec 2003
    Location
    WWW
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i dont even care, how and what table or anything it will use, i just need it asap, its the last thing i need to finish, then i can start this game...
    Run a site? over 1,000 uniques a day? PM me for link exchange.

  14. #14
    Crazy Webmaster Cr0CX's Avatar
    Join Date
    Dec 2003
    Location
    WWW
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh once i got my first code to work i dont remember what i did, but then, a player can get only 1 click a day.. anyone help me?
    Run a site? over 1,000 uniques a day? PM me for link exchange.

  15. #15
    SitePoint Addict loadx's Avatar
    Join Date
    Jul 2004
    Location
    Melbourne, VIC, Australia
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    a player can get only 1 click a day
    i thought the idea was so that the users ip can only click one link per day...?

  16. #16
    Crazy Webmaster Cr0CX's Avatar
    Join Date
    Dec 2003
    Location
    WWW
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah but it was like only 1 click, no matter what ip...
    can you help me recode this?
    Run a site? over 1,000 uniques a day? PM me for link exchange.

  17. #17
    Crazy Webmaster Cr0CX's Avatar
    Join Date
    Dec 2003
    Location
    WWW
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    please people i cant start the game without this...
    Run a site? over 1,000 uniques a day? PM me for link exchange.

  18. #18
    Crazy Webmaster Cr0CX's Avatar
    Join Date
    Dec 2003
    Location
    WWW
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i still need help... if you want you can email at: kdzuba (AT) gmail.com
    Run a site? over 1,000 uniques a day? PM me for link exchange.

  19. #19
    3MTA3
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    1,016
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you run Helge's code, what is displayed for these lines:

    echo "<p>ip: $ip<br />";
    echo "id: $id<br />";
    echo "sql: $sql<br />";
    echo "clicks: $clicks</p>";

  20. #20
    Crazy Webmaster Cr0CX's Avatar
    Join Date
    Dec 2003
    Location
    WWW
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nothing at all!!! not even the <P>IP and </ br> 's
    Run a site? over 1,000 uniques a day? PM me for link exchange.

  21. #21
    Crazy Webmaster Cr0CX's Avatar
    Join Date
    Dec 2003
    Location
    WWW
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and the code is aiit.... i just dont know whats wrong!!!!!!!
    Run a site? over 1,000 uniques a day? PM me for link exchange.

  22. #22
    3MTA3
    Join Date
    Jul 2003
    Location
    Florida
    Posts
    1,016
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post the current code that you're working with?

  23. #23
    Crazy Webmaster Cr0CX's Avatar
    Join Date
    Dec 2003
    Location
    WWW
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?PHP
    include("config.php");
    $ip = $_SERVER['REMOTE_ADDR'];
    $id = $_GET['id'];
    $clicks = mysql_fetch_array(mysql_query("select * from clicks where id=$id and ip='$ip'"));
    if (empty ($clicks)) {
    $givemoney = rand(1, 1500);
    mysql_query("insert into clicks (ip, id) values('$ip','$id')") or die("Could not add click.");
    mysql_query("update players set credits=credits+$givemoney where id=$id");
    $userstat = mysql_fetch_array(mysql_query("select * from players where id=$id"));
    print "<font face=arial size=2>$userstat[user] just got $givemoney credits.</font>";
    exit;
    }
    ?>
    Run a site? over 1,000 uniques a day? PM me for link exchange.

  24. #24
    Employed Again Viflux's Avatar
    Join Date
    May 2003
    Location
    London, On.
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're only checking the first returned result for each ID. That means you're only checking the first person to click on that name. You have to loop through ALL the clicks for the ID to see if the IP has voted for them already.

    I haven't tested this, or even checked for syntax errors, but I think you'll get the idea.

    PHP Code:
    <?php

    include( 'config.php' );

    $ip $_SERVER'REMOTE_ADDR' ];
    $id $_GET'id' ];

    $query 'SELECT * FROM clicks WHERE id=' $id;
    $result mysql_query$query ) or die( 'ERROR!' );

    while( 
    $click mysql_fetch_array$result ) ){
      if( 
    $click['ip'] == $ip ){
        die( 
    'You already voted for this person today.' );
      }
    }

    $givemoney rand(11500);
    $query2 'INSERT INTO clicks (ip , id) VALUES ("' $ip '" , "' $id '")';
    $result2 mysql_queryquery2 ) or die( 'Could not add click.' );
    $query3 'UPDATE players SET credits = credits + ' $givemoney ' WHERE id=' $id;
    $result3 mysql_query$query3 ) or die( 'Could not update player.' );
    $query4 'SELECT * FROM players WHERE id=' $id;
    $result4 mysql_query$query4 ) or die( 'Could not select player.' );
    $userArray msyql_fetch_array$result4 );
    die( 
    $userArray['user'] . ' just got ' $givemoney );

    ?>

  25. #25
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Alternatively, (if I understood the question/ problem correctly)...
    PHP Code:
    <?PHP
    include( 'config.php' ); 
    $ip $_SERVER['REMOTE_ADDR'];
    $id $_GET['id'];
    $clicks mysql_query("select * from clicks where ip='$ip'") or die(mysql_error());
    $rows mysql_num_rows($clicks);
    if (
    $rows==0) {
    $givemoney rand(11500);
    mysql_query("insert into clicks (ip, id) values('$ip','$id')") or die("Could not add click.");
    mysql_query("update players set credits=credits+'$givemoney' where id=$id");
    $userstat mysql_query("select * from players where id=$id");
    $row_stat mysql_fetch_assoc($userstat); ?>
    <font face=arial size=2><? echo $row_stat['id']; ?> just got <? echo $givemoney?> credits.</font>
    <?
    } else {
    echo 
    "Your IP has already been logged";
    }
    ?>
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


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
  •