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 ...
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 ...
6
votes
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 ...
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 ...
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 ...
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 ...
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 "...
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 :
...
2
votes
PHP return validate method of if one error is found
If you are looking for a shorter code you can do this :
...
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 ...
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 ...
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 ...
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 ...
Community wiki
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 ...
1
vote
Validate array elements in PHP
I agree with @Gerrit0 that you should migrate to PHP7. Here is how I would do it:
...
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,...
1
vote
1
vote
Accepted
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 ...
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, ...
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, ...
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 ...
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 ...
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 ...
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 ...
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....
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)
...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
php5 × 229php × 186
object-oriented × 49
performance × 24
pdo × 20
mysql × 19
array × 18
mysqli × 13
classes × 11
laravel × 11
security × 10
beginner × 9
html × 9
mvc × 9
validation × 8
design-patterns × 7
codeigniter × 5
strings × 4
error-handling × 4
cryptography × 4
form × 4
url × 4
symfony2 × 4
sql × 3
datetime × 3