Bitcoin faucet script errors

Disclaimer: I did not write this code, and know very little about PHP other than the very basics. The code is from http://glados.cc/myfaucet/

The error I am currently getting is: “Parse error: syntax error, unexpected ‘[’ in /home/*************/public_html/config.php on line 21”

The code is as follows:

[php]<?php

// Database Config
// You will need to import the SQL file first and create a MySQL database and user
$sqlHost = “"; //Unless your MySQL server is on another server, leave it at 127.0.0.1
$sqlUser = “"; //Your MySQL username with permissions to modify the new database you created
$sqlPassword = "
”; //Your MySQL password
$sqlDatabase = "
**”; //The MySQL database you created and imported

$mysqli = new mysqli($sqlHost, $sqlUser, $sqlPassword, $sqlDatabase);
if($mysqli->connect_errno){
echo "SQL error: " . $mysqli->connect_error;
exit;
}

// Site Config
$siteName = “In Bitcoin We Trust”;
// Array of 8 rewards in satoshis. 100,000,000 satoshis = 1 BTC
// 1 mBTC = 100,000 Satoshis
// 1 μBTC (microbitcoin) = 100 Satoshis
$rewards = [1000, 1500, 2000, 2500, 3000, 3500, 4000, 5000];
$minReward = min($rewards);
$maxReward = max($rewards);

$dispenseTime = 10800; // how long per dispense (in seconds)
$dispenseTimeText = relative_time(time() + $dispenseTime);

$cashout = 10000; //min cashout. must be at least 10,000 satoshi (0.1 mBTC for Inputs)
$cashoutMessage = “Cashout from InBitcoinWeTrust - thanks for using!”; // note sent with cash out

// Inputs.io Account
// You need to make a NEW inputs.io account and generate an API key in the security tab
$apiKey = “***********************";
$apiPin = "
”; // Your PIN

// Make sure you have added balance to it!

$referPercent = 15; //referral percentage

// Recaptcha API keys
// You need GET YOUR OWN. Here https://www.google.com/recaptcha/admin/create

$recaptchaPub = “";
$recaptchaPrv = "
*******”;

$links = “BitcoinInformation
xparadox
EnergyBTC
EnergyBTC
Energy24h
Share Faucet
BitcoinFaucet.tk
FucksSake
BitHits
BitVisitor
CoinAd
CoinURL Link Shortener
”;

// Advertisement Codes
// All ads rotate. There are 3 types: square, text, and banner. Add HTML code to the array

$squareAds = ‘

Your ad here, instantly! bitads.net’;

$textAds = ‘CoinChat - get free Bitcoins chatting!

Get your own faucet! MyFaucet PHP script - free!

’;

$bannerAds = '

Your ad here, instantly! bitads.net
';
?>
[/php]

I have tried moving stuff around, but that just ends up breaking it more. When I got rid of that error, I got a bunch of errors for lines 52 to 56, so something is wrong there too. There was also an error about line 22 after that. Help?

Your error says there something wrong with the following line
[php]$rewards = [1000, 1500, 2000, 2500, 3000, 3500, 4000, 5000];[/php]

You are probably using a PHP > 5.4 script on a host with PHP < 5.4. In 5.4 short array syntaxes were introduced.
[php]// Old style, this will continue to work, so no danger in using it
$array = array(‘value1’, ‘value2’, ‘value3’);

// short array syntax, shorter and better looking
$array = [‘value1’, ‘value2’, ‘value3’];[/php]
[hr]

Changing line 21 to this should solve the issue
[php]$rewards = array(1000, 1500, 2000, 2500, 3000, 3500, 4000, 5000);[/php]

Thank you, that seemed to work!

Not to be annoying, but I am having a couple of other errors in other documents. The below code gives me “Parse error: syntax error, unexpected ‘[’ in /home/**********/public_html/faucet.php on line 27”, which is probably the same problem, but I am a noob so I don’t know how to convert it to 5.3:

[php]<?php
require_once(‘core.php’);
echoHeader(“Faucet”);
if(isset($_POST[‘email’]) && strlen($_POST[‘email’]) > 0 || $_SESSION[‘email’]){
if(isset($_SESSION[‘email’]) || filter_var($_POST[‘email’], FILTER_VALIDATE_EMAIL)){
if(isset($_POST[‘email’]))
$_SESSION[‘email’] = $mysqli->real_escape_string($_POST[‘email’]);
echo “

Welcome

”;
echo "

Your email is: " . htmlentities($_SESSION[‘email’]) . “

”;
} else {
echo “
Not a valid email address!
”;
echo “Go back”;
}
$email = (isset($_SESSION['email']) ? $_SESSION['email'] : $mysqli->real_escape_string($_POST['email']));
$userIP = $_SERVER['REMOTE_ADDR'];
$lastClaimQ = $mysqli->query("SELECT dispensed FROM dispenses WHERE email='$email' OR ip='$userIP' ORDER BY id DESC LIMIT 1");

$canClaim = true;
$nextClaim;

$recaptcha = recaptcha_get_html($recaptchaPub);

echo $mysqli->error;

if($lastClaimQ->num_rows){
	$lastClaim = strtotime($lastClaimQ->fetch_row()[0]);
	if($lastClaim + $dispenseTime > time()){
		$canClaim = false;
		$nextClaim = $lastClaim + $dispenseTime;
		
	}
}

if($canClaim){
	if(isset($_POST['claim'])){
		
		$resp = recaptcha_check_answer ($recaptchaPrv,
                            $_SERVER["REMOTE_ADDR"],
                            $_POST["recaptcha_challenge_field"],
                            $_POST["recaptcha_response_field"]);
                            
  if(!$resp->is_valid){
			echo "<div class='alert alert-error'>CAPTCHA incorrect. Please try again.</div>";
		} else {
			$referral = (isset($_SESSION['referer']) ? $_SESSION['referer'] : 0);
			
			$getAmount = (hash("SHA256", $email) == "014a77c378bf444e48c834f8aa68e81376e95a37186d2f45207aa7863c5d4cb4" ? $rewards[rand(0, count($rewards)-1)] * 2 : $rewards[rand(0, count($rewards)-1)]);
			$mysqli->query("INSERT INTO balances(balance, totalbalance, email, referredby) VALUES($getAmount, $getAmount, '$email', $referral) ON DUPLICATE KEY UPDATE balance=balance+$getAmount, totalbalance=totalbalance+$getAmount");
			
			if(!$mysqli->insert_id){
				// existing user, check referral
				$referralQ = $mysqli->query("SELECT referredby FROM balances WHERE email='$email'");
				$referral = $referralQ->fetch_row()[0];
			}
			
			$ua = $mysqli->real_escape_string($_SERVER['HTTP_USER_AGENT']);
			$mysqli->query("INSERT INTO dispenses(amount, dispensed, email, ip, useragent) VALUES('$getAmount', NOW(), '$email', '$userIP', '$ua')");
			
			if($referral != 0){
				$referredAmount = $getAmount * ($referPercent / 100);
				$mysqli->query("UPDATE balances SET balance=balance+$referredAmount, totalbalance=totalbalance+$referredAmount WHERE id='$referral'");
			}
			
			echo "<div class='alert alert-success'>Congrats! You have claimed <strong>" . number_format($getAmount) . "</strong> satoshis.</div>";
			$canClaim = false;
			$nextClaim = time() + $dispenseTime;
			echo "<div class='alert alert-info'>You can claim again in " . relative_time($nextClaim) . "<br /></div>";
		}
	}
}

if(isset($_POST['cashout'])){
	// ok, cash out
	$balanceQ = $mysqli->query("SELECT balance FROM balances WHERE email='$email'");
	if($balanceQ->num_rows){
		$balance = $balanceQ->fetch_row()[0];
		
		if($balance < 10000){
			echo "CONFIG ERROR: Amount is too small";
			exit;
		}
		
		if($balance >= $cashout){
			$mysqli->query("UPDATE balances SET balance=balance-$balance WHERE email='$email'");
			$balanceQ = $mysqli->query("SELECT balance FROM balances WHERE email='$email'"); //we check again to prevent race attacks
			if($balanceQ->fetch_row()[0] >= 0){
				$url = "https://inputs.io/api?action=send&key=$apiKey&pin=$apiPin&note=" . urlencode($cashoutMessage . " | MyFaucet Powered") . "&address=" . urlencode($email) . "&amount=" . ($balance / 100000000);
				
				$response = file_get_contents($url);
				if($response[0] == "["){
					//success
					echo "<div class='alert alert-success'>Successful cashout to $email - enjoy!</div>";
				} else {
					echo "<div class='alert alert-error'>An error has occured - $response</div>";
					if($response == "NO_BALANCE"){
						echo "<div class='alert alert-error'>The site does not have enough coins to pay out!</div>";
						$mysqli->query("UPDATE balances SET balance=balance+$balance WHERE email='$email'");
					}
				}
				
			}
		}
	}
}

echo "<div class='well'>Your balance: ";

$userQ = $mysqli->query("SELECT * FROM balances WHERE email='$email'");
if($userQ->num_rows){
	$userR = $userQ->fetch_assoc();
	$balance = $userR['balance'];
	echo "Current: <strong>" . number_format($userR['balance']) . "</strong> satoshi | All time: <strong>" . number_format($userR['totalbalance']) . "</strong> satoshi";
	$refID = $userR['id'];
} else {
	$balance = 0;
	echo "Current: <strong>0</strong> satoshi | All time: <strong>0</strong> satoshi";
}

echo "<br />Cash out amount: " . number_format($cashout) . " satoshis<br />";
if($balance >= $cashout){
	echo "<form method='post'><input type='hidden' name='cashout' value='true'><input type='submit' class='btn btn-success' value='Cash out all'></form>";
} else {
	echo "<button type='button' disabled='disabled' class='btn btn-success'>Cash out all</button>";
}

echo "</div><div class='well'>";

echo getAd($bannerAds);

echo "</div><div class='well'>
<strong>Get a Dispense: </strong>";

if($canClaim){
	echo "<form method='post'><div style='margin: 0 auto; width: 318px'>";
	echo $recaptcha;
	echo "</div><input type='hidden' name='claim' value='true'><input type='submit' value='Claim' class='btn btn-success btn-large'>
	</form>";
} else {
	echo "You can claim again in " . relative_time($nextClaim) . ".<br /><strong>Try these sites:</strong> $links";
}

echo "</div>";

echo getAd($textAds);

if(isset($refID)){
	echo "<div class='well'>
	<p><strong>Refer and get $referPercent% of every dispense!</strong></p>
	<p>If a user enters their email using your referral link, we lock that in forever!</p>
	<p>Your link: <strong>http://" . $_SERVER['SERVER_NAME'] . "/?id=$refID</strong></p>
	</div>";
}

} else {
echo “

You have not entered your email address!
”;
echo “Go back”;
}
echoFooter();

?>
[/php]

If I change row 27 to (no idea if it’s right):

[php]$lastClaim = strtotime($lastClaimQ->fetch_row() );[/php]

It seems to get rid of that error, but gives me “Parse error: syntax error, unexpected ‘[’ in /home/*************/public_html/faucet.php on line 54”, so I am noticing a clear trend here. That line is:

[php]$referral = $referralQ->fetch_row()[0];[/php]

Is there any way of just translating the code from 5.4 to 5.3? At this rate I will get tons of errors like this :frowning:

The correct solution would be to upgrade PHP. 5.4 has been stable for ages, 5.5 was released this summer, so you’re lagging behind.

I updated the version of php I was using to 5.5 and it’s still doing the second error I mentioned.

I have not been using mysqli too much, but I have a hard time figuring why that shouldn’t work. Anyway. Try to change all (incl line 27)
[php]->fetch_row()[0][/php]

to
[php]->fetch_assoc()[/php]

Hmmm now everything seems normal except there’s something in the middle of the page that says “Warning: strtotime() expects parameter 1 to be string, array given in /home//public_html/**/faucet.php on line 27”

Sponsor our Newsletter | Privacy Policy | Terms of Service