Hot answers tagged

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 ...
tim's user avatar
  • 25.1k
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.2k
6 votes
Accepted

Get number from N

Maybe you want something short like is echo ($n <= 1) ? 0 : pow(10, $n - 1);
webNeat's user avatar
  • 321
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 ...
Trojan404's user avatar
  • 818
6 votes

Registration code

I am bit puzzled by strip_tags: ...
Kate's user avatar
  • 6,327
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
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 ...
SylvainD's user avatar
  • 29.2k
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 ...
Thijs Riezebeek's user avatar
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 ...
matchilling's user avatar
4 votes

Doctrine/Symfony WHERE clause for reports

I would suggest using the QueryBuilder ...
Filip Procházka's user avatar
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 ...
TMH's user avatar
  • 499
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 ...
tim's user avatar
  • 25.1k
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 ...
tim's user avatar
  • 25.1k
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 ...
Tim McLean's user avatar
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 ...
Jodes's user avatar
  • 340
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, ...
Nick's user avatar
  • 1,480
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 ...
KIKO Software's user avatar
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,588
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

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 ...
FreeLightman's user avatar
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

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 ...
humdash's user avatar
  • 21
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 ...
Dereckson's user avatar
  • 136
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 ...
Marvin Caspar's user avatar
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 ...
mdfst13's user avatar
  • 21.4k
2 votes
Accepted

Mapping a product its corresponding image file

I am going to shorten up some of your code a little bit, ...
Malachi's user avatar
  • 28.6k
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 ...
tim's user avatar
  • 25.1k
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 ...
rivimey's user avatar
  • 121
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 ...
tim's user avatar
  • 25.1k
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 ...
KIKO Software's user avatar

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