This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | |||
3 | include 'php/DatabaseConnect.php'; |
||
4 | include 'php/Location.php'; |
||
5 | include 'php/JodelAccount.php'; |
||
6 | include 'php/Jodel.php'; |
||
7 | include 'php/View.php'; |
||
8 | |||
9 | include 'php/Requests/AbstractRequest.php'; |
||
10 | include 'php/Requests/CreateUser.php'; |
||
11 | include 'php/Requests/GetPosts.php'; |
||
12 | include 'php/Requests/GetKarma.php'; |
||
13 | include 'php/Requests/UpdateLocation.php'; |
||
14 | include 'php/Requests/Upvote.php'; |
||
15 | include 'php/Requests/Downvote.php'; |
||
16 | include 'php/Requests/GetPostDetails.php'; |
||
17 | include 'php/Requests/SendJodel.php'; |
||
18 | include 'php/Requests/GetCaptcha.php'; |
||
19 | include 'php/Requests/PostCaptcha.php'; |
||
20 | include 'php/Requests/GetUserConfig.php'; |
||
21 | include 'php/Requests/GetChannel.php'; |
||
22 | |||
23 | require_once 'php/Requests/libary/Requests.php'; |
||
24 | Requests::register_autoloader(); |
||
25 | |||
26 | $config = parse_ini_file('config/config.ini.php'); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 9 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. ![]() |
|||
27 | $baseUrl = $config['Url']; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 8 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. ![]() |
|||
28 | $buildViewError = ''; |
||
29 | |||
30 | $location = new Location(); |
||
31 | $location->setLat($config['default_lat']); |
||
32 | $location->setLng($config['default_lng']); |
||
33 | $location->setCityName($config['default_location']); |
||
34 | //What is dude doing with my Server? |
||
35 | if($_SERVER['REMOTE_ADDR'] == '94.231.103.52') |
||
36 | { |
||
37 | echo('You are flooting my Server! Pls enable Cookies in your script and contact me: [email protected]'); |
||
38 | die(); |
||
39 | } |
||
40 | |||
41 | View Code Duplication | if(isset($_GET['solution']) && isset($_GET['key']) && isset($_GET['deviceUid'])) |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
42 | { |
||
43 | $jodelAccount = new JodelAccount($_GET['deviceUid']); |
||
44 | $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. ![]() 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 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 ( 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: 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. ![]() |
|||
45 | echo json_encode($response); |
||
46 | |||
47 | die(); |
||
48 | } |
||
49 | |||
50 | function user_log($msg) |
||
0 ignored issues
–
show
As per coding-style, this function should be in camelCase.
![]() |
|||
51 | { |
||
52 | $log = $msg . PHP_EOL; |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 2 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
53 | file_put_contents(realpath(__DIR__ . '/..') . '/logs/user_log-' . date("Y.n.j") . '.txt', $log, FILE_APPEND); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Y.n.j 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 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 ( 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: 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. ![]() |
|||
54 | } |
||
55 | |||
56 | function isUserBot() |
||
0 ignored issues
–
show
isUserBot uses the super-global variable $_SERVER which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
57 | { |
||
58 | preg_match('/bot|spider|google|twitter/i', $_SERVER['HTTP_USER_AGENT'], $matches); |
||
59 | |||
60 | return (isset($matches[0])) ? true : false; |
||
61 | } |
||
62 | |||
63 | function configPropertyExists($config, $property) |
||
64 | { |
||
65 | if(!array_key_exists($property, $config) || !isset($config[$property]) || $config[$property] == '' || $config[$property] == 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') |
||
0 ignored issues
–
show
|
|||
66 | { |
||
67 | return FALSE; |
||
68 | } |
||
69 | else |
||
70 | { |
||
71 | return TRUE; |
||
72 | } |
||
73 | } |
||
74 | |||
75 | function isUserVoter() |
||
0 ignored issues
–
show
isUserVoter uses the super-global variable $_COOKIE which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
76 | { |
||
77 | if(isset($_COOKIE['JodelVoterPassword'])) |
||
78 | { |
||
79 | $db = new DatabaseConnect(); |
||
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. ![]() |
|||
80 | $result = $db->query("SELECT id FROM users WHERE user_token = '" . $_COOKIE['JodelVoterPassword'] . "'"); |
||
81 | View Code Duplication | if($result->num_rows == 0) |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
82 | { |
||
83 | $db->close(); |
||
84 | return FALSE; |
||
85 | } |
||
86 | else |
||
87 | { |
||
88 | $db->close(); |
||
89 | return TRUE; |
||
90 | } |
||
91 | } |
||
92 | else |
||
93 | { |
||
94 | return FALSE; |
||
95 | } |
||
96 | } |
||
97 | |||
98 | function isUserAdmin() |
||
0 ignored issues
–
show
isUserAdmin uses the super-global variable $_COOKIE which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
99 | { |
||
100 | global $config; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
101 | if (isset($_COOKIE['JodelAdminPassword']) && configPropertyExists($config, 'pw') && $config['pw'] == $_COOKIE['JodelAdminPassword']) |
||
0 ignored issues
–
show
|
|||
102 | { |
||
103 | return TRUE; |
||
104 | } |
||
105 | else |
||
106 | { |
||
107 | return FALSE; |
||
108 | } |
||
109 | } |
||
110 | |||
111 | function isDeviceUidInDatabase($deviceUid) |
||
112 | { |
||
113 | $db = new DatabaseConnect(); |
||
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. ![]() |
|||
114 | $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $deviceUid . "'"); |
||
115 | |||
116 | View Code Duplication | if ($result->num_rows > 0) |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
117 | { |
||
118 | $db->close(); |
||
119 | return TRUE; |
||
120 | } |
||
121 | else |
||
122 | { |
||
123 | $db->close(); |
||
124 | return FALSE; |
||
125 | } |
||
126 | } |
||
127 | |||
128 | //Check if it's a Spider or Google Bot |
||
129 | if(configPropertyExists($config, 'botDeviceUid') && isUserBot()) |
||
130 | { |
||
131 | user_log('Spider or Bot checked in!'); |
||
132 | |||
133 | $jodelAccountForView = new JodelAccount($config['botDeviceUid'], TRUE); |
||
134 | } |
||
135 | else |
||
136 | { |
||
137 | if(!isset($_COOKIE['JodelDeviceId']) || !isDeviceUidInDatabase($_COOKIE['JodelDeviceId'])) |
||
138 | { |
||
139 | $jodelAccountForView = new JodelAccount(); |
||
140 | setcookie('JodelDeviceId', $jodelAccountForView->deviceUid, time()+60*60*24*365*10); |
||
141 | user_log('Created account with JodelDeviceId:' . $jodelAccountForView->deviceUid . ' for [' . $_SERVER ['HTTP_USER_AGENT'] . ']'); |
||
0 ignored issues
–
show
|
|||
142 | |||
143 | } |
||
144 | else |
||
145 | { |
||
146 | $jodelAccountForView = new JodelAccount($_COOKIE['JodelDeviceId']); |
||
147 | } |
||
148 | |||
149 | } |
||
150 | |||
151 | if(configPropertyExists($config, 'karmaDeviceUid')) |
||
152 | { |
||
153 | $jodelAccountForKarma = new JodelAccount($config['karmaDeviceUid']); |
||
154 | } |
||
155 | else |
||
156 | { |
||
157 | error_log("No Karma deviceUid set in config file"); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
No Karma deviceUid set in config file 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 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 ( 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: 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. ![]() |
|||
158 | $jodelAccountForKarma = new JodelAccount($deviceUid); |
||
159 | } |
||
160 | |||
161 | /* |
||
162 | * Cunstruct View |
||
163 | */ |
||
164 | |||
165 | $hashtag = ''; |
||
166 | |||
167 | if(isset($_GET['search'])) |
||
168 | { |
||
169 | |||
170 | user_log('User with JodelDeviceId:' . $jodelAccountForView->deviceUid . ' [' . $_SERVER['REMOTE_ADDR'] . '][' . $_SERVER ['HTTP_USER_AGENT'] . '] searched for ' . $_GET['search']); |
||
0 ignored issues
–
show
|
|||
171 | |||
172 | if(substr($_GET['search'], 0, 1) === "#") |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
# 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 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 ( 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: 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. ![]() |
|||
173 | { |
||
174 | if(strrpos($_GET['search'], ' ') == NULL) |
||
175 | { |
||
176 | $hashtag = substr($_GET['search'], 1); |
||
177 | } |
||
178 | else |
||
179 | { |
||
180 | $hashtag = substr($_GET['search'], 1, strrpos($_GET['search'], ' ')); |
||
181 | |||
182 | $city = substr($_GET['search'], |
||
183 | strrpos($_GET['search'], ' ') + 1, |
||
184 | strlen($_GET['search'])); |
||
185 | |||
186 | if($city != NULL && $city != '') |
||
187 | { |
||
188 | $_GET['city'] = $city; |
||
189 | } |
||
190 | } |
||
191 | } |
||
192 | else |
||
193 | { |
||
194 | $_GET['city'] = $_GET['search']; |
||
195 | } |
||
196 | } |
||
197 | $hashtag = trim($hashtag); |
||
198 | |||
199 | if($hashtag == '') |
||
200 | { |
||
201 | if(isset($_GET['hashtag'])) |
||
202 | { |
||
203 | $hashtag = $_GET['hashtag']; |
||
204 | } |
||
205 | else |
||
206 | { |
||
207 | $hashtag = '#all'; |
||
208 | } |
||
209 | } |
||
210 | |||
211 | //Set Location |
||
212 | if(isset($_GET['city']) && $_GET['city'] != '' && !$jodelAccountForView->locationEquals($_GET['city'])) |
||
213 | { |
||
214 | $cityName = $jodelAccountForView->setLocation(); |
||
215 | } |
||
216 | else |
||
217 | { |
||
218 | $cityName = $jodelAccountForView->location->getCityName(); |
||
219 | } |
||
220 | |||
221 | |||
222 | |||
223 | if(isset($_GET['view'])) |
||
224 | { |
||
225 | switch ($_GET['view']) { |
||
226 | case 'discussed': |
||
227 | $view = 'discussed'; |
||
228 | break; |
||
229 | |||
230 | case 'popular': |
||
231 | $view = 'popular'; |
||
232 | break; |
||
233 | |||
234 | default: |
||
235 | $view = 'combo'; |
||
236 | break; |
||
237 | } |
||
238 | } |
||
239 | else |
||
240 | { |
||
241 | $view = 'combo'; |
||
242 | } |
||
243 | |||
244 | if(isset($_GET['postId'])) |
||
245 | { |
||
246 | $view = new View($baseUrl, 'DE', $cityName, $hashtag, $view, $_GET['postId']); |
||
247 | } |
||
248 | else |
||
249 | { |
||
250 | $view = new View($baseUrl, 'DE', $cityName, $hashtag, $view); |
||
251 | } |
||
252 | |||
253 | $newPositionStatus = ''; |
||
254 | if($hashtag != '#all') |
||
255 | { |
||
256 | $newPositionStatus = '#' . $hashtag . ' '; |
||
257 | } |
||
258 | $newPositionStatus .= $cityName; |
||
259 | |||
260 | //Verify Account |
||
261 | if(isset($_GET['solution']) && isset($_GET['key']) && isset($_GET['deviceUid'])) |
||
262 | { |
||
263 | $jodelAccountForVerify = new JodelAccount($_GET['deviceUid']); |
||
264 | $jodelAccountForVerify->verifyCaptcha(); |
||
265 | } |
||
266 | |||
267 | //SendJodel |
||
268 | if(isset($_POST['message'])) |
||
269 | { |
||
270 | $errorMsg = $jodelAccountForView->sendJodel($jodelAccountForView->location, $view); |
||
271 | } |
||
272 | ?> |
||
0 ignored issues
–
show
It is not recommended to use PHP's closing tag
?> in files other than templates.
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore. A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever. ![]() |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.