ArtisticPhoenix
  • Member for 6 years, 6 months
  • Last seen more than a month ago
Writing a ~100Kb HTML string over an MD file (number of iterations ~10K)
Accepted answer
6 votes

This is what I meant in the comments You could do substr($hey,0,2) once and then check the first two letters instead of multiple strpos. Maybe, but I have no idea what $hey looks like :) - but than ...

View answer
Sanitizing name strings using PHP
Accepted answer
4 votes

I would clean it up a bit: public static function slugCompany($company){ $replace = [ '/[^\da-z\s]/i' => '', //remove punctuation I guess '/\b('.self::...

View answer
Elegant and secure way to create a dynamic query
3 votes

If you allow users to pass in arguments that are column names (for example array keys that you turn into column names). Then the keys could be modified to allow SQL Injection. It's not clear in the ...

View answer
Codeigniter 3: how can I avoid repeating this chunk of code in my controllers?
3 votes

In this case I would probably convert this $this->Static_model into a Config file that I can use through CI (that is what they are there for). You can even make CI load this file automatically, ...

View answer
Program that prints star pattern
Accepted answer
3 votes

It looks nice. Can you please make me understand how it works For example function f($n){$s='';$b=str_pad('*',($m=$n*2+1),' ',2);for($i=0;$i<$m;++$i)$s.=($i==$n)?str_repeat('*',$m):$b;return ...

View answer
Refactoring my controllers with a BaseController to remove repetitive code?
2 votes

Lets look at your code namespace App\Controllers; class Welcome extends { private $twig; public function __construct(\Twig_Environment $twig) { $this->twig = $twig; } ...

View answer
Load other files (from outside public_html) under index.php
Accepted answer
2 votes

Preface I wouldn't use the query string of the URL at all. The problem with using GET, is that GET is meant for other things such as bookmarkable search link etc. As you add more do stuff in your ...

View answer
PHP Secure Login Scripts
2 votes

The only thing I see that I would like to see changed is this if($user === false){ die('Incorrect username / password combination!'); } else { ... } Here you are relying on "very" strict ...

View answer
PHP Class used in Drupal 8 module
Accepted answer
2 votes

You'll have to take some of these at face value as I don't use Drupal. I looked at this purely from a logical and structural view point, So there are probably a few things going on here i may not ...

View answer
Processing document file takes forever
2 votes

Well for starters here is a good example public function ValidateDocument($FileName, $UploadName){ $PrevUploadName = basename($this->RequestFields->GetField('UploadName')); if(strlen($...

View answer
PHP library that can use different authentication mechanisms
1 votes

I would lay it out something like this: interface AuthenticableInterface { public function getName(): string; /** * Based on auth type, return the right format of credentials to be sent ...

View answer
PHP - Packing widgets into the fewest number of boxes, plus minimum order quantity
1 votes

Here is one using a while loop and simple subtaction: $packSizes = [250,500,1000,2000,5000]; $number = 3000; function optimizePacks($packSizes,$number) { //insure packs are in ...

View answer
Import class using OOP
1 votes

As I said in the comments: For errors, that's harder to say. Use exceptions for validation errors, catch them in the CSV reading loop, so you can continue reading. You'll have to decide what state ...

View answer
PHP login system with prevention for session hijacking, fixation, injection, etc
1 votes

A few things I noticed, First of all this is plain wrong (if it's pure PDO): $link->query("SELECT useragent_hash, user_ip FROM users WHERE username = :username"); $link->bind(':username', $...

View answer
Use a comma-separated field in another SQL query
Accepted answer
1 votes

Not withstanding what other have mentioned. $array = explode(",",$data->items); // string here is 39,40,41 $items = implode("','",$array); // string here is 39','40','41 You can simply replace ...

View answer
Image-uploading
1 votes

Building on what others have said, I would for sure do this in the background. There are a number of mature message queues that are very easy to setup and get running. RabbitMq, is one that I am ...

View answer