Welcome, guest! Please login or register.

    * Shoutbox

    RefreshHistory
    • Travas: your mom is a pussy
      January 19, 2018, 01:01:55 AM
    • stCky: yeah so at least my mom has a pussy
      January 18, 2018, 12:29:06 AM
    • Travas: your mom is a faggot
      January 17, 2018, 08:21:57 PM
    • stCky: mom wont let me meet internet strangers
      January 17, 2018, 04:20:53 PM
    • Saltyspade10: Moparmeetupppp
      January 16, 2018, 07:07:04 PM
    • stCky: but my car is japanese
      January 16, 2018, 07:06:25 PM
    • Saltyspade10: Mopar meet up?
      January 16, 2018, 07:05:59 PM
    • stCky: pfft my rb25det cefiro will eat ur tiny 1960s v8 for breakfast kid
      January 16, 2018, 07:01:30 PM
    • Travas: fag
      January 16, 2018, 01:16:43 PM
    • Oblit: ph*
      January 16, 2018, 12:34:04 PM
    • Oblit: pk balance
      January 16, 2018, 12:33:17 PM
    • Travas: racist bigot
      January 15, 2018, 09:33:12 PM
    • stCky: wheres the fun in that you immagint synthesizer
      January 15, 2018, 09:24:14 PM
    • Travas: no trump no kkk no fascist usa
      January 15, 2018, 09:11:29 PM
    • stCky: im lit
      January 15, 2018, 07:49:10 PM
    • Travas: hi
      January 15, 2018, 07:21:21 PM
    • runerunerune: hi
      January 15, 2018, 05:44:20 AM
    • shulker: anyone selling onyx? trade me in game ill negotiate an offer for like 5 trades per person
      January 15, 2018, 12:56:09 AM
    • Travas: o shit wadup
      January 14, 2018, 11:59:49 PM
    • stCky: pass me that blunt boi u know whats up
      January 14, 2018, 06:50:41 PM

    Author Topic: [317] Give users GP for voting on a website! [317]  (Read 24110 times)

    0 Members and 1 Guest are viewing this topic.

    Offlineammarscape

    • Member
    • **
    • Posts: 9
    • Thanks: +0/-0
      • View Profile
    [317] Give users GP for voting on a website! [317]
    « on: April 26, 2010, 08:13:42 AM »
    Note: I did not write the code in this tutorial. The code was originally created by iVariable. MoparScape didn't have this tutorial so i decided to re-write and release it. All coding credits go to iVariable.

    Purpose: Gives people GP/items for voting on a website.
    Difficulty: 5 (It just uses MySQL, that doesn't make it rise to 10...)
    Tested on: Czar, Delta

    WEBSITE SIDE

    -> A webserver/hosting account with MySQL working.
    -> COM SQL driver ()
    -> A website obviously

    In your web hosting make a new PHP file and call it vote.php, add the following in to it:
    Code: [Select]
    <?php

    $host
    ="localhost";
    $username="YOUR MYSQL USERNAME";
    $password="YOUR MYSQL PASSWORD";
    $db_name="DATABASE NAME";

    $link mysql_connect("$host""$username""$password")or die("cannot connect");
    mysql_select_db("$db_name")or die("cannot select DB");

    $username=$_POST['username'];
    $voteid = ($_POST['votenum']);

    $username stripslashes($username);
    $username mysql_real_escape_string($username);

    $time time();
    $ip $_SERVER['REMOTE_ADDR'];

    if(clean_requests($time))
    {
    if(vote_entries($ip) == 0)
    {
    mysql_query("INSERT INTO Votes (username, ip, time, recieved) VALUES ('$username', '$ip', '$time', '0')"$link) or die("An internal error has occured please try again later.<br/>To go back click <a href='index.php'><b>HERE</b></a>");
    header("Location: ".votenow($voteid)."");
    }
    else
    {
    die("You have already voted once today<br/>To go back click <a href='index.php'><b>HERE</b></a>");
    }
    }
    else
    {
    die("An internal error has occured please try again later.<br/>To go back click <a href='index.php'><b>HERE</b></a>");
    }

    function 
    clean_requests($time)
    {

    $query mysql_query "SELECT * FROM Votes");
    $i 0;
    while($row mysql_fetch_array($query))
    {
    $i++;
    $timerequested $row['time'];
    if($time-$timerequested 12*3600)
    {
    if (!mysql_query"DELETE FROM Votes WHERE time='$timerequested'"))
    {
    return false;
    }
    }
    }
    return true;
    }

    function 
    vote_entries($ip)
    {
    $entries mysql_query "SELECT * FROM Votes WHERE ip = '$ip'" );
    if ( !$entries ) {
    die ( "Unable to get number of entries: " mysql_error () );
    }
    return mysql_num_rows $entries );
    }

    function 
    votenow($votenum)
    {
    $url "";
    if($votenum)
    {
    switch($votenum)
    {
    case 1:
    $url "VOTE LINK 1;
    break;

    case 2:
    $url = "VOTE LINK 2";
    break;

    case 3:
    $url = "VOTE LINK 3";
    break;

    default: die("
    Error!"); break;
    }
    }
    return 
    $url;
    }

    ?>

    The above code has three voting websites configured to work with it. If you need more, just ask me, it's easy to add a few more. Just a copy paste of code required.

    You will need to replace the following variables with your MySQL Details, if you don't have them, ask your host:
    YOUR MYSQL USERNAME
    YOUR MYSQL PASSWORD
    DATABASE NAME

    If you haven't already create a new database and call it whatever you like. I called mine vote. Your MySQL details may look like this:

    YOUR MYSQL USERNAME: ammaris1_vote
    YOUR MYSQL PASSWORD: 738883hdgry7
    DATABASE NAME: vote

    Now, time to explain: The above PHP code connects to the database and when you vote, it inserts the username, time and a given variable of 0 when you vote the first time.

    Now, open PhpMyAdmin you probably have it, if you don't ask your host to configure it for you. In PhpMyAdmin, open the newly created database and run this SQL query on it:

    Code: [Select]
    CREATE TABLE IF NOT EXISTS `votes` (
      `username` char(50) DEFAULT NULL,
      `ip` char(50) DEFAULT NULL,
      `time` int(50) DEFAULT NULL,
      `recieved` int(1) DEFAULT NULL
    )
    This query creates the tables that are needed to insert the information.

    Now go back to your file manager and create a HTML file, this time call it vote.html. Add this code into it:
    Code: [Select]
    <form name="form" method="post" action="vote.php">
    Username:  <input name="username" type="text" id="username">
    Vote #  <select name="votenum">
    <option value="1">VOTE WEBSITE 1</option>
    <option value="2">VOTE WEBSITE 2</option>
    <option value="3">VOTE WEBSITE 3</option>
    </select><br/><br/>
    <input type="submit" value="Vote!"/>
    </form>
    This code connects to vote.php and this is where your players enter their username and where they want to vote. Replace VOTE WEBSITE 1, VOTE WEBSITE 2 and VOTE WEBSITE 3 with the places they are voting, if you don't want to use all 3 spaces just remove the whole line of code where VOTE WEBSITE # is mentioned.
    -----------------------------------------------------------------------------------------------------------
    Server Side

    This is the part that most people get wrong. Add your COM driver which you downloaded into your server files and then make a new Java file called MYSQL.java (With capitals). Add this into it:
    Code: [Select]
    import java.sql.*;
    import java.security.MessageDigest;

    public class MYSQL {

    public static Connection con = null;
    public static Statement stm;

    public static void createConnection() {
    try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    con = DriverManager.getConnection("jdbc:mysql://127.0.0.1/database", "username", "password");
    stm = con.createStatement();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    public static ResultSet query(String s) throws SQLException {
    try {
    if (s.toLowerCase().startsWith("select")) {
    ResultSet rs = stm.executeQuery(s);
    return rs;
    } else {
    stm.executeUpdate(s);
    }
    return null;
    } catch (Exception e) {
    misc.println("MySQL Error:"+s);
    e.printStackTrace();
    }
    return null;
    }

    public static void destroyCon() {
    try {
    stm.close();
    con.close();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    public static boolean checkVotes(String playerName)
    {
    try {
    Statement statement = con.createStatement();
    String query = "SELECT * FROM Votes WHERE username = '" + playerName + "'";
    ResultSet results = statement.executeQuery(query);
    while(results.next()) {
    int recieved = results.getInt("recieved");
    if(recieved == 0)
    {
    return true;
    }

    }
    } catch(SQLException e) {
    e.printStackTrace();
    }
    return false;
    }
    public static boolean voteGiven(String playerName)
    {
    try
    {
    query("UPDATE Votes SET recieved = 1 WHERE username = '" + playerName + "'");
    } catch (Exception e) {
    e.printStackTrace();
    return false;
    }
    return true;
    }
    }
    Search for this code: "jdbc:mysql://127.0.0.1/database", "username", "password"
    Replace database with your database name and username and password with your MySQL details.

    Now, go to your login method, this can be found by searching your welcome text. Under the last bracket in it, add this code.
    Code: [Select]
    if(MYSQL.checkVotes(playerName)){
    if(freeSlots() > 2)
    {
    if(MYSQL.voteGiven(playerName))
    {
    giveItem(995,5000000);
    sendMessage("Thank you for voting!");
    }
    }else{
    sendMessage("You do not have enough free space to receive items");
    }
    }

    This code is for Czar Bases, if you want to use Delta, use the following code.
    Code: [Select]
    if(MYSQL.checkVotes(playerName)){
    if(freeSlots() > 2)
    {
    if(MYSQL.voteGiven(playerName))
    {
    addItem(995,5000000);
    sM("Thank you for voting!");
    }
    }else{
    sM("You do not have enough free space to receive items");
    }
    }

    Now save and compile, you should not get any errors, post any here and I'll try to help.

    Now go to www.YOURWEBSITE.com/vote.html, enter your username, pick a place to vote and vote! You should have some money in your inventory after you log in.

    If you want to change the item given or the amount of money, change giveItem(995,5000000); this code.

    Credits:
    -> iVariable 80%
    -> Me 20% at the most, i just typed it up all over again.

    Post any problems/comments below!
    RS2Ad banner

    Offlinespy man47

    • Member
    • ****
    • Posts: 1,861
    • Thanks: +0/-0
      • View Profile
    Re: [317] Give users GP for voting on a website! [317]
    « Reply #1 on: April 26, 2010, 08:51:57 AM »
    Very nice job! Rep+

    Btw will this screw up highscores?
    I am muted!! WAHAHAHAHAHAHA

    To contact this user, Just simply message him.

    But he will not be able to message you.
    RS2Ad banner

    Offlineammarscape

    • Member
    • **
    • Posts: 9
    • Thanks: +0/-0
      • View Profile
    Re: [317] Give users GP for voting on a website! [317]
    « Reply #2 on: April 26, 2010, 11:03:51 AM »
    No it wont screw up highscores because they run completely separated and thanks for the rep :)
    RS2Ad banner

    OfflineSvitkona

    • Member
    • ****
    • *
    • Posts: 4,675
    • Thanks: +1/-0
      • View Profile
    Re: [317] Give users GP for voting on a website! [317]
    « Reply #3 on: April 26, 2010, 12:50:13 PM »
    nice, but maybe you should make it add the items to the player's bank in case the player has no space in his backpack.
    ... i really have to learn sql...
    I've always been mad, I know I've been mad, like the most of us...very hard to explain why you're mad, even if you're not mad...

    Offlineammarscape

    • Member
    • **
    • Posts: 9
    • Thanks: +0/-0
      • View Profile
    Re: [317] Give users GP for voting on a website! [317]
    « Reply #4 on: April 27, 2010, 01:16:56 PM »
    The code doesn't give the person the money if they have no space, it's in the code. If you want it to be like that, you can code it in. If the person doesn't have the space, they'll get it when they log in and have some space.

    Offline$erver owner

    • Member
    • **
    • Posts: 19
    • Thanks: +0/-0
      • View Profile
    Re: [317] Give users GP for voting on a website! [317]
    « Reply #5 on: April 27, 2010, 01:35:25 PM »
    Could you do it for 508?
    Owner Of Tomi-Scape

    Offlinedemonlover14

    • Member
    • ****
    • Posts: 614
    • Thanks: +0/-0
      • View Profile
    Re: [317] Give users GP for voting on a website! [317]
    « Reply #6 on: April 27, 2010, 01:58:12 PM »
    Repped, this is very nice.
    And, "$erver owner" this wasit made by him.
    LINK: demons.smfforfree2.com sick server:)*Altarnate website is demonsworld.netne.net*
    I promise you'll like it.
    My 100th rep by Mr.Despair!
    You can also request a tutorial on my forums:)

    Offline$erver owner

    • Member
    • **
    • Posts: 19
    • Thanks: +0/-0
      • View Profile
    Re: [317] Give users GP for voting on a website! [317]
    « Reply #7 on: April 27, 2010, 03:35:34 PM »
    how can we do it on 508?
    Owner Of Tomi-Scape

    OfflinePouch

    • Member
    • ***
    • Posts: 232
    • Thanks: +0/-0
      • View Profile
    Re: [317] Give users GP for voting on a website! [317]
    « Reply #8 on: April 27, 2010, 03:44:10 PM »
    if(MYSQL.checkVotes(playerName)){
    if(freeSlots() > 2)
    {
    if(MYSQL.voteGiven(playerName))
    {
    addItem(995,5000000);
    sM("Thank you for voting!");
    }
    }else{
    sM("You do not have enough free space to receive items");
    }
    }

    that makes you get 5m per time u login if u voted at least once..

    fix it
    "96% of people won't stand up for God
    Put this in your Sig if you are one of the 4% who will"

    OfflineDavidi2

    • Member
    • ****
    • *
    • Posts: 23,272
    • Thanks: +0/-0
      • View Profile
    Re: [317] Give users GP for voting on a website! [317]
    « Reply #9 on: April 27, 2010, 04:05:29 PM »
    Why are people repping him if he didn't make the tutorial? Instead of taking other people's work, you could ask them to register so they can get the credit.

    OfflineJohn459

    • Member
    • ****
    • Posts: 1,079
    • Thanks: +0/-0
      • View Profile
    Re: [317] Give users GP for voting on a website! [317]
    « Reply #10 on: April 27, 2010, 06:30:01 PM »
    Leeched
    Physics > *

    OfflineSpades

    • Member
    • ****
    • Posts: 2,459
    • Thanks: +0/-0
      • View Profile
    Re: [317] Give users GP for voting on a website! [317]
    « Reply #11 on: April 27, 2010, 07:17:20 PM »
    Leeched

    Where'd you get that idea from?

    Note: I did not write the code in this tutorial. The code was originally created by iVariable. MoparScape didn't have this tutorial so i decided to re-write and release it. All coding credits go to iVariable.

    And your only supposed to post your own work.

    OfflineJohn459

    • Member
    • ****
    • Posts: 1,079
    • Thanks: +0/-0
      • View Profile
    Re: [317] Give users GP for voting on a website! [317]
    « Reply #12 on: April 27, 2010, 07:40:38 PM »
    Right here:




    Hopefully you know what to change run-srv to.
    Physics > *

    OfflineJaydenD12

    • Member
    • ****
    • Posts: 1,321
    • Thanks: +0/-0
      • View Profile
    Re: [317] Give users GP for voting on a website! [317]
    « Reply #13 on: April 28, 2010, 02:41:09 AM »
    Great job, I'm impressed.
    20% cooler

    Offlineammarscape

    • Member
    • **
    • Posts: 9
    • Thanks: +0/-0
      • View Profile
    Re: [317] Give users GP for voting on a website! [317]
    « Reply #14 on: April 28, 2010, 07:18:40 AM »
    If you don't like it don't post, and i know i didn't make it. It doesn't hurt to 100% retype the whole thing and make it so much easier to add. If your inexperienced, it would take you a pretty long time to work out how to add the one on run3-srv. If you think what i did is against the rules, go ahead, get it removed, i'm just trying to help mopar

    Offlinespy man47

    • Member
    • ****
    • Posts: 1,861
    • Thanks: +0/-0
      • View Profile
    Re: [317] Give users GP for voting on a website! [317]
    « Reply #15 on: April 28, 2010, 08:00:31 AM »
    Doen't listen to them, w.E they say...
    I am muted!! WAHAHAHAHAHAHA

    To contact this user, Just simply message him.

    But he will not be able to message you.

    Offlineammarscape

    • Member
    • **
    • Posts: 9
    • Thanks: +0/-0
      • View Profile
    Re: [317] Give users GP for voting on a website! [317]
    « Reply #16 on: April 28, 2010, 09:29:40 AM »
    Thanks for being on my side :)

    Offlinedemonlover14

    • Member
    • ****
    • Posts: 614
    • Thanks: +0/-0
      • View Profile
    Re: [317] Give users GP for voting on a website! [317]
    « Reply #17 on: April 28, 2010, 02:02:49 PM »
    Leeched
    Uhh. . .
    No duh?
    He said he did...
    LINK: demons.smfforfree2.com sick server:)*Altarnate website is demonsworld.netne.net*
    I promise you'll like it.
    My 100th rep by Mr.Despair!
    You can also request a tutorial on my forums:)

    OfflineThe Soul

    • MoparScape Vet
    • Member
    • ****
    • *
    • Posts: 5,354
    • Thanks: +0/-0
      • View Profile
    Re: [317] Give users GP for voting on a website! [317]
    « Reply #18 on: April 28, 2010, 04:02:42 PM »
    And your only supposed to post your own work.

    Yes, though an exception is if the original creator of the tutorial is accredited appropriately.
    <Jc22493> ts how was sex
    <Lin> he was okay

    OfflineJohn459

    • Member
    • ****
    • Posts: 1,079
    • Thanks: +0/-0
      • View Profile
    Re: [317] Give users GP for voting on a website! [317]
    « Reply #19 on: April 28, 2010, 06:25:32 PM »
    Leeched
    Uhh. . .
    No duh?
    He said he did...


    I posted that before he edited his post and admitted to leeching it.
    Physics > *

     

    Copyright © 2017 MoparScape. All rights reserved.
    Powered by SMFPacks SEO Pro Mod |
    SimplePortal 2.3.5 © 2008-2012, SimplePortal