ParadiseX
Would you like to react to this message? Create an account in a few clicks or log in to continue.

ParadiseX

The greatest Runescape private Server.
 
HomePortalSearchLatest imagesRegisterLog inMedia

 

 ALLEN HERES MY GUIDE ABOUT THAT VOTE!!

Go down 
3 posters
AuthorMessage
DaviD

DaviD


Posts : 19
Join date : 2010-01-02

ALLEN HERES MY GUIDE ABOUT THAT VOTE!! Empty
PostSubject: ALLEN HERES MY GUIDE ABOUT THAT VOTE!!   ALLEN HERES MY GUIDE ABOUT THAT VOTE!! Icon_minitimeSun Jan 03, 2010 1:25 pm

YO IS THIS WHAT U WERE ASKIN ABOUT I CAN MAKE?

For this you must have
A webserver with MYSQL
COM SQL connection driver (http://uppit.com/v/DZIS72L4)
Some PHP and Java Knowledge would be handy
HTML know how
PHP:
Code:
<?php
$host="localhost";
$username="username";
$password="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 = "http://www.xtremetop100.com/in.php?site=00000;
break;
case 2:
$url = "http://www.gtop100.com/in.php?site=00000";
break;
case 3:
$url = "http://www.mmorpgtoplist.com/in.php?site=00000";
break;
default: die("Error!"); break;
}
}
return $url;
}
?>


Ok now to explain, I ran into a little problem of not having cron jobs on my webserver, so I had to create a few timer functons.
The script will insert the username, users IP and also a unix timestamp and a given variable of 0 once they vote the first time.

Code:
$time = time();
$ip = $_SERVER['REMOTE_ADDR'];
mysql_query("INSERT INTO Votes (username, ip, time, recieved) VALUES ('$username', '$ip', '$time', '0')", $link)

Now once we have that information if, the user trys to vote again, the unix time when called is put into a variable and the timestamp is also fetched from the SQL server, we then do a simply bit of maths, timestampnow - timestamthen = time we need to check to see when they last voted.
If the time they last voted is less then 12 hours (43200 unix) then the script will end and say you have already voted once today, I have set it to 12 hours due to most vote websites you may vote every 12 hours, ok now if the sum is bigger then (43200 unix) then that SQL row will be deleted, allowing for the user to re vote.
The script gets the URL # and username from a form which posts the data to Vote.php on the server.
Example HTML form:
Code:
<form name="form" method="post" action="vote.php">
Username: <input name="username" type="text" id="username">
Vote # <select name="votenum">
<option value="1">1</option>
<option value="3">2</option>
</select><br/><br/>
<input type="submit" value="Submit"/>
</form>


Ok now we get to the java side of it:

Code:
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;
}
}


Ok the above code, connects to the MYSQL server using the com SQL driver, we then have checkVotes(), this will query the sql database to see if the given username is there, it will then check the recieved var of the row, to see if they have already been given there vote reward.
voteGiven() updated the recieved variable in the sql row to 1 showing the user has already been given the reward.
I will now show you how I use these function on my login method of my server:

I am not going to spoon feed users on information of how to use this, I have included the com driver and the scripts examples to use this.
Rememeber to use the MYSQL class you will need to connect to the database once the server is loaded:
Code:

MYSQL.createConnection();

I hope this gives some insite into how SQL information can be processed using Java and also PHP, this can be used for many things, I have used something like this for my automation item giver, which uses Paypal callback script once a user makes a payment they are auto given the item as they login.

-DaviD

PS READ IT!


I will try answer any questions users have or errors, remember this will need altering to the server you use, delta for example does not use my same functions it uses, sM("Message here"), addItem(item, amount);, if you run into 100 errors you are missing a } or {, use a programme such as Notepad++ or Eclipse IDE for syntax help.
Back to top Go down
https://paradisex.forumotion.net
Necro




Posts : 13
Join date : 2010-01-02

ALLEN HERES MY GUIDE ABOUT THAT VOTE!! Empty
PostSubject: Re: ALLEN HERES MY GUIDE ABOUT THAT VOTE!!   ALLEN HERES MY GUIDE ABOUT THAT VOTE!! Icon_minitimeSun Jan 03, 2010 2:46 pm

You must love you code
Back to top Go down
owner unborn
Admin



Posts : 12
Join date : 2010-01-02

ALLEN HERES MY GUIDE ABOUT THAT VOTE!! Empty
PostSubject: thank you!!   ALLEN HERES MY GUIDE ABOUT THAT VOTE!! Icon_minitimeSun Jan 03, 2010 3:24 pm

ok thanks now ill get started on this. IF YOU CAN , PLEASE SET UP THE FOLDER VOTE AND INSIDE HAVE THE FILES READY AND UPLOAD TO MEDIAFIRE THAT WOULD HELP ALOT!!!! if you cant ill do all this Smile
Back to top Go down
https://paradisex.forumotion.net
 
ALLEN HERES MY GUIDE ABOUT THAT VOTE!!
Back to top 
Page 1 of 1
 Similar topics
-
» VOTE NOW!!!
» Compile Guide
» Price Guide
» PRICE GUIDE FROM CRISIS(OUR SOURCE!)v1

Permissions in this forum:You cannot reply to topics in this forum
ParadiseX :: Announcements-
Jump to: