Skip to main content
7 votes

Registration code

The code is horrible. It probably contains all of the top 10 vulnerabilities listed on the OWASP web site. It uses a programming language that is well-known for its bad security history and its ...
Roland Illig's user avatar
  • 21.9k
6 votes

Security of post submission, picture upload and post fetch

Please read about sql injection. Basically you should be using prepared statements with parameters for executing SQL queries - either PDO::prepare() or ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
6 votes

Registration code

I am bit puzzled by strip_tags: ...
Kate's user avatar
  • 8,778
3 votes

Appending objects to an array based on a field

If $statement contains a huge amount of data I'm assuming the 6500 records are in the $statement iterator, and that the $statement iterator somehow will fetch data from a database. Just removing the ...
Arend's user avatar
  • 178
2 votes

Optimized solution for a rolling dice code puzzle

@Mr AJ already gave you a valid answer on the algorithmic approach in his Java example, but since it seems Java is unfamiliar to you, I will just write out the algorithm here in a way that hopefully ...
Mike Brant's user avatar
  • 9,878
2 votes

Optimized solution for a rolling dice code puzzle

With extra O(n) space the complexity can be made O(n) only, without sorting that will take ...
Mr X's user avatar
  • 173
2 votes

Parsing multipart/form-data in php for PUT requests

Based on your work I derived the following code from it. The previous code had for example problems with multiple attached files. Also I would avoid setting the ...
Michael's user avatar
  • 21
2 votes

Split words that are too big

Normally I take the time to study Mike Brant's answers (because they are so frequently educational to me), but this time it was tl;dr. If this was my project, I'd specifically/exclusively target the "...
mickmackusa's user avatar
  • 8,802
2 votes

Code for a Person DTO, with tests

In the tests (and anywhere else), you should use constants to ensure correct spelling of the properties : ...
Geompse's user avatar
  • 121
2 votes

PHP return validate method of if one error is found

If you are looking for a shorter code you can do this : ...
Geompse's user avatar
  • 121
2 votes

Merging and summing multi-dimensional arrays

Presuming that the format will be consistent, you could remove one foreach loop and extract the domain to use as the key of the merged array, and also only either ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
2 votes
Accepted

Users management php class

Whole user management system is very hard to do properly even with structural code. When you get a grasp of entire logic & security nuances OOP itself takes it to the next level, because this ...
shudder's user avatar
  • 696
2 votes

Security of post submission, picture upload and post fetch

Alas, an online search for 'php tutorial' returns plenty of outdated tutorials, some of which are downright dangerous (SQL injections). It's no wonder newcomers to PHP perpetuate bad code and bad ...
Kate's user avatar
  • 8,778
2 votes
Accepted

php swiftmailer two message instances with one mailer instance?

Note: this is intended to be a Community wiki since it was taken from a deleted answer by yannis; The suggestion to do this was here Using two message instances is fine as is most of your code. There ...
2 votes
Accepted

PHP - Importing columns from uploaded CSV file to SQL database (Laravel 5.7)

I defined the fields that I wanted to be required first. Then, I defined a One-to-Many relationship between an account table and a contacts table where the contact id is the account's name in the ...
Victor Melvin's user avatar
1 vote

Validate array elements in PHP

I agree with @Gerrit0 that you should migrate to PHP7. Here is how I would do it: ...
nforced's user avatar
  • 171
1 vote
Accepted

Validate array elements in PHP

First: Upgrade PHP!!! PHP 5.6 is losing security support on December 31st this year. Ref. All other PHP 5 versions are completely unsupported. You should be running PHP 7 today. Once you've done that,...
Gerrit0's user avatar
  • 3,501
1 vote

Users management php class

Early Returns I prefer early returns for example ...
Dan's user avatar
  • 530
1 vote
Accepted

Quiz setting users grade

You could use an array of grades: ...
Toto's user avatar
  • 579
1 vote

Git Autoupdater

Why have you repeated if ($_DEBUG) echo a zillion times? That is begging to be embedded in a debug() function. Every time you ...
Bryan B's user avatar
  • 211
1 vote
Accepted

Sync Server Time with User's Timezone

Some thoughts: Consider using the timestamp-generation functionality of your database for record insert use cases. This way the database holds authority over the timezone used for the application, ...
Mike Brant's user avatar
  • 9,878
1 vote

Sync Server Time with User's Timezone

I personally would have saved it as a simple timestamp rather than a date, whether or not that's actually a better idea is debatable, but a timestamp requires half as much space as a datetime and is, ...
I wrestled a bear once.'s user avatar
1 vote

Merge sort in PHP 5

It appears that you have quite a bit of experience with mergesort in various programming languages. While it may obviously be deemed a bit tangential to the purpose of StackOverflow I can’t help but ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
1 vote

Write a HTML table from MySQL tables

As others pointed out in comments, the question about the difference between .ajax() and .load() should be and does exist on SO ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
1 vote

Laravel controller for a commenting system

First of all; your controller does too many things. You may need to move your database related queries out of the controller. Repositories maybe? Also use Eloquent it is one of the most powerful way ...
Ersoy's user avatar
  • 131
1 vote

Database wrapper class

Create method Perhaps the create method should ensure $data is not empty - otherwise it could lead to SQL errors. Throwing an ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
1 vote

Sorting an array to match the order of values of another array

You don't need to call any sort() functions because your input and response arrays have a 1-to-1 relationship. Flip your input array so that the values become keys....
mickmackusa's user avatar
  • 8,802
1 vote

Optimized solution for a rolling dice code puzzle

After reading the other answers that speak in depth on the theory and big O, I thought I would script up my interpretation. Code: (Demo with echoed variables to show values and processes) ...
mickmackusa's user avatar
  • 8,802
1 vote

Conditionally truncating a filename to a max length without damaging the file extension

For anyone who "is bad at conditionals", the good news is that this script can be sensibly written with only one conditional. I am electing to use a ternary expression in my custom function -- this ...
mickmackusa's user avatar
  • 8,802

Only top scored, non community-wiki answers of a minimum length are eligible