9
votes
Accepted
How to use PHP Visibility method?
Yes, the original code is awful. It is 200 lines of spaghetti code; I have no idea what it does, it is impossible to reuse and extremely difficult to test, debug, or change.
That doesn't necessarily ...
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
Accepted
6
votes
Accepted
A Search Engine Class
I really like the structure of your code. That said, I almost never suggest to give class variables default values. That is what the constructor is for. For that matter, you don't need to specify that ...
6
votes
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 ...
5
votes
Get number from N
The pow function is probably what you are looking for.
return pow(10, $n-1); should be close to what you want but might need ...
5
votes
Accepted
PHP class which preserves line break by splitting the line into as many line break as it have
After about 10 minutes of reading your code and testing it out, I think I figured out what your class is supposed to, which is not a good sign for such a small class.
To me it seems that the goal of ...
5
votes
Accepted
PHP Class code that allow developers to register taxonomies in a CMS
I think you're mixing too many ideas here and as a consequence your class ends up having too many responsibilities, which than need extensive documentation because their behaviour may not be obvious ...
4
votes
3
votes
PHP form validation for name, email, and Twitter handle
Here are just few things I noticed.
Class names
I always try and use uppercase first letters, so DataException rather than ...
3
votes
Accepted
Updating register_globals code for importing $_GET and $_POST data
This seems a bit complex for relatively little benefit. Personally, from these two choices, I would go with the isset approach for simplicity and slightly improved ...
3
votes
PHP page pagination
Yes, mixing PHP and HTML can get messy quite quickly.
If you do not want to switch to some templating engine, the easiest way to clean this up is to build the entire HTLM block in a PHP variable and ...
3
votes
Accepted
Secure array encryption and decryption
First, a note on style. When I write encryption code, I like to encapsulate as much crypto-related logic inside the encrypt and ...
3
votes
Classes, one responsibility principle and magic methods
Firstly, I'd just like to start by saying that I believe __get and __set magic methods are bad practice, and should be reserved ...
3
votes
Accepted
Authorizing users for POST requests
I do not see much thing to review, except goto.
Code style...
...is OK.
I will suggest functions to be no more than 10-15 lines, ...
3
votes
PHP program which extracts attribute lists from custom tag
Here are some things I noticed:
The function splitByDelimiter() is no more than a wrapper around explode(). Why not use ...
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
Routing for a Laravel 5 e-commerce site
I do not know if your admin controllers are in the separate folder, but I see that they have the same prefix - admin. Laravel has such route groups.
So you can ...
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
is_numeric_array() is missing
This is an old post, but if you're looking for a shorter but still elegant solution, use this:
return array_values($array) === $array
You could even use it as ...
2
votes
Accepted
Calculating a quality score of something based on attributes
This approach sounds logically good, as it allows to determine how much the profile has been completed. There seems to exist a correlation between people completing their profile fully and giving ...
2
votes
Accepted
Multilanguage class that detects and sets language
The class is small and simple but I just made some changes for better reading.
I'm a fan of exit early so if an if statement is checked and there is nothing more to do, exit the function. the rest ...
2
votes
Accepted
PHP page pagination
Checking if a variable is set
if (isset($_GET["page_num"]) && $_GET["page_num"] >= 2): ?>
Here you check if ...
2
votes
Accepted
Mapping a product its corresponding image file
I am going to shorten up some of your code a little bit,
...
2
votes
Accepted
Using PHP's password_hash and password_verify for a login function
Would this be the correct usage of password_hash and password_verify to log the user into the site
Yes. You didn't post your password_hash code, but you are using password_verify correctly, so if ...
2
votes
Bulk customer creation
Initial thoughts on this code:
one long and very convoluted chunk. It badly needs refactoring into smaller and more easily understood pieces.
various commented out lines, which obscure the logic.
SQL ...
2
votes
Accepted
Forum project using OOP PHP
back: I'm not sure what this function is used for (and the name doesn't seem that great), but it is open to XSS. An attacker could create a page at ...
2
votes
Lookup class to get descriptions of values
Getting a distinct list from MySQL would slow things down quite a bit, I wouldn't do that.
Perhaps you're overdoing it a bit? Yes, it is always good to filter user input, but I would do that at the ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
php5 × 231php × 186
object-oriented × 50
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
database × 4
cryptography × 4
form × 4
url × 4
symfony2 × 4
sql × 3