Thread: PI

Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1 PI 
    Registered Member
    Morphine's Avatar
    Join Date
    Jul 2011
    Posts
    1,814
    Thanks given
    495
    Thanks received
    262
    Rep Power
    136
    Something is wrong with my vote 4 cash

    Need help too,

    Code:
    <?php 
    
    /** 
     * @author Stuart <Exile-nation | iVariable> 
     * @version 1.1 UPDATED: 06.09.2010 
     * @comment fixed a few bugs 
     */ 
    
    /** 
     * mysql database hostname 
     */ 
    define("MYSQL_HOST", "212.1.210.1"); 
    /** 
     *  mysql username to connect to the database server 
     */ 
    define("MYSQL_USERNAME", "exiledna_ing"); 
    /** 
     *  mysql password the password to connect to the database server 
     */ 
    define("MYSQL_PASSWORD", "Exiless"); 
    /** 
     *  mysql database the database name in which you have your vote table setup 
     */ 
    define("MYSQL_DATABASE", "exiledna_Vote"); 
    /** 
     *  vote url this is the url which where users will be sent to on voting 
     */ 
    define("VOTE_URL", "/vote.html"); 
    /** 
     * The number of hours between voting 
     */ 
    define("VOTE_HOURS", 1); 
    
    
    /** 
     *  connect() this function is used to connect to the mysql database server. 
     */ 
    function connect() 
    { 
        if (!@mysql_connect(212.1.210.1, exiledna_ing, exiles)) 
            die("Could not connect to mysql database: " . mysql_error()); 
        if (!@mysql_select_db(exiledna_Vote)) 
            die("Could not select mysql database: " . mysql_error()); 
        $tables = mysql_list_tables(exiledna_Vote); 
        while (list($temp) = mysql_fetch_array($tables)) { 
            if ($temp == "votes") { 
                return; 
            } 
        } 
        query("CREATE TABLE `votes` ( 
            `playerName` VARCHAR( 255 ) NOT NULL , 
            `ip` VARCHAR( 255 ) NOT NULL, 
            `time` BIGINT NOT NULL , 
            `recieved` INT( 1 ) NOT NULL DEFAULT '0')"); 
    } 
    /** 
     *  query(string query) this function is used to query the mysql database server. 
     */ 
    function query($s) 
    { 
        $query = @mysql_query($s); 
        if (!$query) 
            die("Error running query('" . $s . "'): " . mysql_error()); 
        return $query; 
    } 
    /** 
     *  anti_inject(string text) this function is used to make sure no injections can be made. 
     */ 
    function anti_inject($sql) 
    { 
        $sql = preg_replace(sql_regcase("/(from|select|insert|delete|where|drop table|show tables|#|\*|--|\\\\)/"), 
            "", $sql); 
        $sql = trim($sql); 
        $sql = strip_tags($sql); 
        $sql = addslashes($sql); 
        $sql = strtolower($sql); 
        return $sql; 
    } 
    /** 
     *  clean_request(int timestamp, string username) this function is used to delete any entries if they have already expired. 
     */ 
    function clean_request($time, $username) 
    { 
        $query = query("SELECT * FROM `votes` WHERE `playerName`='" . $username . "'"); 
        if (mysql_num_rows($query) > 0) { 
            $row = mysql_fetch_array($query); 
            $timerequested = $row['time']; 
            if ($time - $timerequested > VOTE_HOURS * 60) 
                query("DELETE FROM `votes` WHERE time='" . $timerequested . "'"); 
        } 
    } 
    /** 
     *  vote_entries(string ip) this function is used return the number of rows within the table 
     */ 
    function vote_entries($ip) 
    { 
        $query = query("SELECT * FROM `votes` WHERE ip='" . $ip . "'"); 
        return mysql_num_rows($query); 
    } 
    
    
    /** 
     * This is the actual working of the script please do not touch anything below if you do not know what you are doing... 
     */ 
    if (isset($_POST['submit']) || isset($_GET['username']) && isset($_GET['type'])) { 
        connect(); 
        if ($_POST['submit']) { 
            if(@fsockopen($_SERVER['REMOTE_ADDR'], 80, $errno, $errstr, 1)) 
                die("Sorry but you have port 80 open, this is to stop voting by proxy address."); 
            if(isset($_COOKIE['voted'])) 
                die("Sorry but it looks like you have already voted..."); 
            $username = anti_inject($_POST['username']); 
            $ip = gethostbyaddr($_SERVER['REMOTE_ADDR']); 
            clean_request(time(), $username); 
            if (vote_entries($ip) == 0) { 
                setcookie ("voted", "yes", VOTE_HOURS * 60); 
                query("INSERT INTO `votes` (`playerName`, `ip`, `time`) VALUES ('" . $username . 
                    "', '" . $ip . "', '" . time() . "')"); 
                header("Location: " . VOTE_URL . ""); 
            } else { 
                die("You have already voted once today."); 
            } 
        } elseif ($_GET['type'] == "checkvote") { 
            $username = anti_inject($_GET['username']); 
            $query = query("SELECT * FROM `votes` WHERE `playerName`='" . $username . "'"); 
            if (mysql_num_rows($query) == 1) { 
                $results = mysql_fetch_array($query); 
                if ($results['recieved'] == 0) { 
                    query("UPDATE `votes` SET `recieved`='1' WHERE `playerName`='" . $username . "'"); 
                    die("user needs reward..."); 
                } else { 
                    die("user been given reward..."); 
                } 
            } else { 
              die("Vote not found... ".  $username ."."); 
            } 
        } 
    } 
    
    ?> 
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>Exile vote</title> 
    </head> 
    <body> 
    <div align="center" style="color:#5CB3FF"><h2>Vote for a reward!</h3></div> 
    <table align="center"> 
    
    <form action="vote.php" method="post"> 
      <tr> 
        <td align="right">In-Game Username: </td> 
        <td><input name="username" type="text" /></td> 
      </tr> 
      <tr> 
              <td>&nbsp;</td> 
        <td align="center"><input type="submit" name="submit" value="SUBMIT!" /></td> 
      </tr> 
    
    </form> 
    </table> 
    </body> 
    </html>

    Error code

    Parse error: syntax error, unexpected T_DNUMBER in /home/exiledna/public_html/vote.php on line 40


    original code for the vote.php

    Code:
    <?php
    
    /**
     * @author Stuart <RogueX | iVariable>
     * @version 1.1 UPDATED: 06.09.2010
     * @comment fixed a few bugs
     */
    
    /**
     * mysql database hostname
     */
    define("MYSQL_HOST", "localhost");
    /**
     *  mysql username to connect to the database server
     */
    define("MYSQL_USERNAME", "sqlusername");
    /**
     *  mysql password the password to connect to the database server
     */
    define("MYSQL_PASSWORD", "sqlpass");
    /**
     *  mysql database the database name in which you have your vote table setup
     */
    define("MYSQL_DATABASE", "sqldatabase");
    /**
     *  vote url this is the url which where users will be sent to on voting
     */
    define("VOTE_URL", "http://www.google.com/toplist/index.php?action=vote&id=102");
    /**
     * The number of hours between voting
     */
    define("VOTE_HOURS", 24);
    
    
    /**
     *  connect() this function is used to connect to the mysql database server.
     */
    function connect()
    {
        if (!@mysql_connect(MYSQL_HOST, MYSQL_USERNAME, MYSQL_PASSWORD))
            die("Could not connect to mysql database: " . mysql_error());
        if (!@mysql_select_db(MYSQL_DATABASE))
            die("Could not select mysql database: " . mysql_error());
        $tables = mysql_list_tables(MYSQL_DATABASE);
        while (list($temp) = mysql_fetch_array($tables)) {
            if ($temp == "votes") {
                return;
            }
        }
        query("CREATE TABLE `votes` (
            `playerName` VARCHAR( 255 ) NOT NULL ,
            `ip` VARCHAR( 255 ) NOT NULL,
            `time` BIGINT NOT NULL ,
            `recieved` INT( 1 ) NOT NULL DEFAULT '0')");
    }
    /**
     *  query(string query) this function is used to query the mysql database server.
     */
    function query($s)
    {
        $query = @mysql_query($s);
        if (!$query)
            die("Error running query('" . $s . "'): " . mysql_error());
        return $query;
    }
    /**
     *  anti_inject(string text) this function is used to make sure no injections can be made.
     */
    function anti_inject($sql)
    {
        $sql = preg_replace(sql_regcase("/(from|select|insert|delete|where|drop table|show tables|#|\*|--|\\\\)/"),
            "", $sql);
        $sql = trim($sql);
        $sql = strip_tags($sql);
        $sql = addslashes($sql);
        $sql = strtolower($sql);
        return $sql;
    }
    /**
     *  clean_request(int timestamp, string username) this function is used to delete any entries if they have already expired.
     */
    function clean_request($time, $username)
    {
        $query = query("SELECT * FROM `votes` WHERE `playerName`='" . $username . "'");
        if (mysql_num_rows($query) > 0) {
            $row = mysql_fetch_array($query);
            $timerequested = $row['time'];
            if ($time - $timerequested > VOTE_HOURS * 3600)
                query("DELETE FROM `votes` WHERE time='" . $timerequested . "'");
        }
    }
    /**
     *  vote_entries(string ip) this function is used return the number of rows within the table
     */
    function vote_entries($ip)
    {
        $query = query("SELECT * FROM `votes` WHERE ip='" . $ip . "'");
        return mysql_num_rows($query);
    }
    
    
    /**
     * This is the actual working of the script please do not touch anything below if you do not know what you are doing...
     */
    if (isset($_POST['submit']) || isset($_GET['username']) && isset($_GET['type'])) {
        connect();
        if ($_POST['submit']) {
            if(@fsockopen($_SERVER['REMOTE_ADDR'], 80, $errno, $errstr, 1))
                die("Sorry but you have port 80 open, this is to stop voting by proxy address.");
            if(isset($_COOKIE['voted']))
                die("Sorry but it looks like you have already voted...");
            $username = anti_inject($_POST['username']);
            $ip = gethostbyaddr($_SERVER['REMOTE_ADDR']);
            clean_request(time(), $username);
            if (vote_entries($ip) == 0) {
                setcookie ("voted", "yes", VOTE_HOURS * 3600);
                query("INSERT INTO `votes` (`playerName`, `ip`, `time`) VALUES ('" . $username .
                    "', '" . $ip . "', '" . time() . "')");
                header("Location: " . VOTE_URL . "");
            } else {
                die("You have already voted once today.");
            }
        } elseif ($_GET['type'] == "checkvote") {
            $username = anti_inject($_GET['username']);
            $query = query("SELECT * FROM `votes` WHERE `playerName`='" . $username . "'");
            if (mysql_num_rows($query) == 1) {
                $results = mysql_fetch_array($query);
                if ($results['recieved'] == 0) {
                    query("UPDATE `votes` SET `recieved`='1' WHERE `playerName`='" . $username . "'");
                    die("user needs reward...");
                } else {
                    die("user been given reward...");
                }
            } else {
              die("Vote not found... ".  $username .".");
            }
        }
    }
    
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Vote for a reward!</title>
    </head>
    <body>
    <div align="center" style="color:#00F"><h2>Vote for a reward!</h3></div>
    <table align="center">
    
    <form action="vote.php" method="post">
      <tr>
        <td align="right">Username: </td>
        <td><input name="username" type="text" /></td>
      </tr>
      <tr>
              <td>&nbsp;</td>
        <td align="center"><input type="submit" name="submit" value="Vote now" /></td>
      </tr>
    
    </form>
    </table>
    </body>
    </html>
    Tell me what i've done wrong?
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Jul 2012
    Posts
    30
    Thanks given
    9
    Thanks received
    5
    Rep Power
    0


    Shitty code.
    Reply With Quote  
     

  3. #3  
    Registered Member
    Morphine's Avatar
    Join Date
    Jul 2011
    Posts
    1,814
    Thanks given
    495
    Thanks received
    262
    Rep Power
    136
    :x everyone says to use that, is there a better voting i can use?
    Reply With Quote  
     

  4. #4  
    Ignorance is always an excuse

    Mikee's Avatar
    Join Date
    Nov 2009
    Posts
    2,370
    Thanks given
    732
    Thanks received
    490
    Rep Power
    656
    Error seems to be happening where you changed

    Code:
        if (!@mysql_connect(MYSQL_HOST, MYSQL_USERNAME, MYSQL_PASSWORD))
    to

    Code:
        if (!@mysql_connect(212.1.210.1, exiledna_ing, exiles))
    apparently this can be caused by forgetting to put the closing PHP tag ?> before dealing with HTML code?

    I usually just stick to Java so I'm not sure if what I'm telling you is of any use.



    The day Aj repped me, my life changed forever
    Quote Originally Posted by Aj View Post
    Rep++ for you
    Reply With Quote  
     

  5. #5  
    Registered Member
    Morphine's Avatar
    Join Date
    Jul 2011
    Posts
    1,814
    Thanks given
    495
    Thanks received
    262
    Rep Power
    136
    Quote Originally Posted by Mikee View Post
    Error seems to be happening where you changed

    Code:
        if (!@mysql_connect(MYSQL_HOST, MYSQL_USERNAME, MYSQL_PASSWORD))
    to

    Code:
        if (!@mysql_connect(212.1.210.1, exiledna_ing, exiles))
    apparently this can be caused by forgetting to put the closing PHP tag ?> before dealing with HTML code?

    I usually just stick to Java so I'm not sure if what I'm telling you is of any use.
    idk man, i followed everything on the guide
    Reply With Quote  
     

  6. #6  
    Registered Member
    Morphine's Avatar
    Join Date
    Jul 2011
    Posts
    1,814
    Thanks given
    495
    Thanks received
    262
    Rep Power
    136
    Bump...?
    Reply With Quote  
     

  7. #7  
    Registered Member
    Morphine's Avatar
    Join Date
    Jul 2011
    Posts
    1,814
    Thanks given
    495
    Thanks received
    262
    Rep Power
    136
    bump
    Reply With Quote  
     

  8. #8  
    Registered Member
    Join Date
    Feb 2011
    Posts
    359
    Thanks given
    10
    Thanks received
    9
    Rep Power
    10
    I'll bump for you. Hope you find your solution.
    Also you could messed something up, try re-adding it.
    Reply With Quote  
     

  9. #9  
    Registered Member
    Morphine's Avatar
    Join Date
    Jul 2011
    Posts
    1,814
    Thanks given
    495
    Thanks received
    262
    Rep Power
    136
    @shawn, i tried everything first without looking @ tuts & got an error & looked @ tuts and still got the error.
    Reply With Quote  
     

  10. #10  
    Registered Member
    Morphine's Avatar
    Join Date
    Jul 2011
    Posts
    1,814
    Thanks given
    495
    Thanks received
    262
    Rep Power
    136
    bump!?!??
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

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