Jump to content
  • 0
Sign in to follow this  
madman

auto vote for my server web side

Question

[code]
<?php

/**
* mysql database hostname
*/
define("MYSQL_HOST", "*******");
/**
* mysql username to connect to the database server
*/
define("MYSQL_USERNAME", "*****");
/**
* mysql password the password to connect to the database server
*/
define("MYSQL_PASSWORD", "******");
/**
* mysql database the database name in which you have your vote table setup
*/
define("MYSQL_DATABASE", "*****");
/**
* Where you want them redirected after voting
*/
define("VOTE_URL", "/forums");
/**
* 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 ( [MENTION=103481]Mysql[/MENTION]_connect(MYSQL_HOST, MYSQL_USERNAME, MYSQL_PASSWORD))
die("Could not connect to mysql database: " . mysql_error());
if ( [MENTION=103481]Mysql[/MENTION]_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 = [MENTION=103481]Mysql[/MENTION]_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 .".");
}
}
}

?>

<html>
<head>
<title>Raging-Nemesis - Vote4Cash</title>
<style type="text/css">
body {

background-color: #222222;
font-family:Arial;
}
.link {
cursor:pointer;
color: #037;
text-decoration: underline;
}
.link:hover {
color: #ADD8E6;
}
.link-done {
cursor:pointer;
color: #222222;
text-decoration: line-through;
}
.link-done:hover {
color: #ADD8E6;
}
#container {

background-color: #222222;
height: auto;
width: 500px;
padding: 5px;
border: 1px solid #ADD8E6;
margin: 0 auto auto auto;
-moz-box-shadow: 0 0 5px #ADD8E6;
-webkit-box-shadow: 0 0 5px #ADD8E6;
box-shadow: 0 0 5px #ADD8E6;
}

#help {


background-color: #222222;
height: auto;
width: 500px;
padding: 5px;
border: 1px solid #222222;
margin: 0 auto auto auto;
-moz-box-shadow: 0 0 5px #ADD8E6;
-webkit-box-shadow: 0 0 5px #ADD8E6;
box-shadow: 0 0 5px #ADD8E6;
}
</style>
<script type="text/javascript">
var timer;
var timeLeft = 30;

var voted1 = false;
var voted2 = false;
var voted3 = false;
var voted4 = false;
var voted5 = false;

function clickedLink(button) {
switch(button) {
case 1:
voted1 = true;
javascript:window.open('http://www.runelocus.com/toplist/vote-17816.html', '60', 'left = 20, top = 20, width = 800, height = 600, toolbar = 0, resizable = 0, scrollbars=1');
document.getElementById("vote1").setAttribute("class", "link-done");
break;
case 2:
voted2 = true;
javascript:window.open('http://www.rune-server.org/top.php?act=vote&sid=6746', '60', 'left = 20, top = 20, width = 800, height = 600, toolbar = 0, resizable = 0, scrollbars=1');
document.getElementById("vote2").setAttribute("class", "link-done");
break;
}

setSitesLeft();
if (voted1 && voted2) {
startCountDown();
document.getElementById('statusText').style.display = 'none';
}
}

function startCountDown() {
timer = setInterval("doCountDown();", 1000);
document.getElementById('timerText').style.display = 'block';
}

function doCountDown() {
document.getElementById('timeLeft').innerHTML = timeLeft;
timeLeft = (timeLeft - 1);
if (timeLeft <= 0) {
document.getElementById('links').style.display = 'none';
document.getElementById('voted').style.display = 'block';
clearTimeout(timer);
}
}

function setSitesLeft() {
var count = 2;
if (voted1) {
count = (count - 1);
}
if (voted2) {
count = (count - 1);
}
if (voted3) {
count = (count - 1);
}
if (voted4) {
count = (count - 1);
}
if (voted5) {
count = (count - 1);
}
document.getElementById('sitesLeft').innerHTML = count;
}
</script>
</head>

<body>
<center><img src="http://i.imgur.com/k8lBZ.png" /></center><br />
<div id="help"><strong>How It Works:</strong><br /><br />Vote on each of the links below once you have voted on all of them you will be forwarded to A page that will allow you to input your username. When you are on this page make sure you put in your username and accept. Once in game type ::voted to receive your reward!</div><br />

<div id="container">
<div id="links">
1. <a id="vote1" onclick="clickedLink(1);" class="link">RuneLocus</a> <br>
2. <a id="vote2" onclick="clickedLink(2);" class="link">Rune-Server</a> <br>

<span id="statusText">Click & vote at all the links above to continue, only <b id="sitesLeft">2</b> left.</span>
<span id="timerText" style="display: none;">You have <b id="timeLeft">*</b> seconds left before you can claim you reward. </span>
</div>

<div id="voted" style="display: none;">
<form action="vote.php" method="post">
<center>Username: <input type="text" name="username" /> <input type="submit" name="submit" value="Claim Reward!" /></center>
</form>
</div>
</div>
</body>
</html>
[/code]
im using godaddy mysql there using php 5.0 i could use some help with this although i payed some1 to do it but they keep telling me to switch host which im not paying more money for.

idk where to put this :/ ill move it if its wrong sec

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0
If your not able to create a Sql connection.
then just create a Php script and then post the information to the site

Share this post


Link to post
Share on other sites
Sign in to follow this  

×