Completed
Push — master ( 306300...8aacdd )
by mains
02:51
created

vote-ajax.php (4 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
$config = parse_ini_file('config/config.ini.php');
4
if(!isset($_GET['pw']) || $config['pw'] != $_GET['pw'])
5
{
6
	error_log($_SERVER['REMOTE_ADDR']  . ' used a wrong password on vote-ajax.php');
7
	$respone = array("message" => $_SERVER['REMOTE_ADDR']  . ' used a wrong password on vote-ajax.php',"success" => false);
8
	echo json_encode($response);
9
	
10
	die();
11
}
12
13
include 'php/jodel-web.php';
14
15
if(isset($_GET['solution']) && isset($_GET['key']) && isset($_POST['deviceUid']))
16
{
17
	$jodelAccount = new JodelAccount($_POST['deviceUid']);
18
	$response = array("success" => $jodelAccount->verifyCaptcha());
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
Coding Style Comprehensibility introduced by
The string literal success does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
19
	echo json_encode($response);
20
	die();
21
}
22
23
$message = "";
24
$success = true;
25
$token = "";
26
	if(isset($_POST['vote']) && isset($_POST['postId']))
27
	{
28
		$i = 0;
29
		$result = $db->query("SELECT access_token, device_uid FROM accounts WHERE device_uid NOT IN (SELECT device_uid FROM votes WHERE postId = '" . $_POST['postId'] . "')");
30
31
		if($result->num_rows > 0)
32
		{
33
			$row = $result->fetch_assoc();
34
			$accessToken = $row['access_token'];
35
			$deviceUid = $row['device_uid'];
36
			
37
			$jodelAccount = new JodelAccount($deviceUid);
38
39
			if(!$jodelAccount->isAccountVerified())
40
			{
41
				$view = new View();
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
42
				$message = "This account is not verified. Please verify this account first.";
43
				$captcha = $view->getCaptcha($accessToken);
44
				$success = false;
45
			}
46
			else
47
			{
48
				$jodelAccount->votePostId($_POST['postId'], $_POST['vote']);
49
			}
50
		}
51
		else
52
		{
53
			$message = 'There is no account available for this jodel. Please create at least one new account to vote this jodel.';
54
			$success = false;
55
		}
56
	}
57
58
if (isset($captcha))
59
{
60
	$response = array("success" => $success, "message" => $message, "captcha" => $captcha, "deviceUid" => $deviceUid);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal deviceUid does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
61
}
62
else 
63
{
64
	$response = array("success" => $success, "message" => $message);
65
}
66
echo json_encode($response);
67
?>