Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

3

Trying to avoid duplicating any comments you have already had Why name the class "ST"? It's not very clear to another developer what a class called ST actually does Why extend EQ? Generally inheritance is use to make another class that provides the same functionality but more specialised, e.g. A "Car" might extend a class "Vehicle". I think it would be a ...


2

I would say your code is pretty good for a beginner. Of course in time it could grow up, along with your own experience but for the current level it is mostly ok. There are mostly minor improvements bootstrap.php You may notice that a certain block of code is repeated in every file. Once you see a repetition it's signal for refactoring. Here it's simple ...


3

First, let me review some of of the code you have public function getTodoList() { return $this->oConnection->query('SELECT * FROM t_todolist')->fetchAll(); } This is actually all the code you need for this task. Just one line. Thanks PDO being not an ordinary database driver like mysqli. You can check other PDO wonders in my article There is ...


1

There are many improvements you could make, but you're on the right track. In this answer I will only comment on some of the things I immediately notice. Coding style It is difficult to get an overview of your code. There's little organization. I would have split this code up into multiple files. For instance: There will be more PHP files on your server ...


2

I don't see a great deal to refine with this snippet -- good work. $ticker_stats["quote"], can be safely omitted from the isset() call because the subsequent checks on its subarrays will do the necessary work. Good work supplying multiple parameters to a single isset() call. I may be able to refine the following section, but would need realistic sample ...


2

Welcome to Code Review. Your code is understandable, so we can, more or less, figure out what it does, but it is always nice for reviewers to hear you say what you use a piece of code for, what its purpose is, what the code itself specifically does, and to have some usage examples. This also helps you to reflect on the choices you made. I couldn't get your ...


3

As soon as you are finished using your $stmt object, it is practical to close it. However, I find that I am never calling $stmt->close(); in any of my projects because php is going to trash them as soon as my script is done anyhow. Technically, you could have called it one line earlier. Some leisure reading: $stmt->close() vs $stmt->free_result() When ...


0

So the high delay was a result of the Stripe API calls, as it appears they have a limit of you pulling data. To improve this, I changed it so I pull all the data I need from the API into my database when specific actions are performed, then call the data I need from my own database instead of constantly bothering the API: function update_stripe_meta() { ...


0

Disclaimer, I'm not a PHP guru. Just looked at your code and did a bit of optimization; I feel it needs more. By the way, you're right. The problem is in the function calls. <?php use Stripe\Stripe; use Stripe\Customer; use Stripe\Subscription; Stripe::setApiKey("api_key"); /** * You could declare this at the top of the file * $stripeSubId = ...


2

The code can be slightly improved, but it won't make much of a difference overall. This whole approach seems a bit weird. Why does the JSON file exist in the first place? Here is the 'improved' version: <?php // read the json file on the server $txt = file_get_contents("json"); // get the id of the application $id = filter_input(INPUT_GET, "id", ...


-1

Its better to use factory pattern for creating custom errors. I'm working on Java and following Java code might be helpful: class CsvException extends Exception { public static final int USEREXISTS = 7; public static final int MAILINVALID = 1; public static final int SEALUSED = 2; public static final int MIXEDUP = 3; public static final ...


1

This is how I ended up doing it now: <?php namespace App\Registration\GroupUploads\Errors; /** * Error that appear during parsing csv file * @var [type] */ abstract class Error { const USEREXISTS = 7; const MAILINVALID = 1; const SEALUSED = 2; const MIXEDUP = 3; const QUALMISSING = 20; public $id; protected $msg; /** * ...


3

Object Oriented Programming Improvements The first thing you can do to improve code like this is to use dependency injection, instead of instantiating objects with new inside of objects. // Setup your class hierarchies like this. abstract class Controller { protected $model; protected function __construct(Model $model) { $this->...


1

I’m not sure if you still maintain this code but if so, you could consider using a FormData object. I see it has been documented on MDN since 2015 and the link to the specification points to whatwg.org, which has been archived since 2012. I found a post on SO from 2011 that uses it. That way you wouldn’t have to manually query the DOM for inputs (I.e. var ...


2

Given an answer on Stack Overflow suggests almost identical code for protection, let alone using exactly the same principle you can safely assume that your query is protected. If you want to know how it works, I also wrote an answer on Stack Overflow, https://stackoverflow.com/a/8265319/285587 Nevertheless, as this site is for the code reviews offering ...


2

As an overarching rule, I never write scripts with the "stfu operator" (@). It looks like you plan to refine the session starting line, so I won't dwell. You are calling time() 5 separate times in your function. Because there is no benefit in recording their differences in terms of microseconds, I recommend that you call time() once, and cache the value in ...


0

I don't use $_SESSION super global array and don't know much about it, so please correct me if I'm wrong, isn't this code vulnerable to session fixation attacks ? AFAIK the magic behind $_SESSION is a session id cookie, I think it's default name is PHPSESSID, and in your code when the user logs in you don't change this cookie! I did little test before I ...


3

I'll take a more holistic approach than mickmackusa, he already talked about a lot of details. I don't see any problem with the fact that you use an AJAX call to verify user credentials, and login. There's no real difference, security wise, when I compare this with a normal form submission. Any hacker will simply bypass your Javascript and call login.inc....


5

isset() accepts multiple parameters, you can simplify: if (isset($parameters["inserted_id"]) && isset($parameters["inserted_password"])) { To if (isset($parameters["inserted_id"], $parameters["inserted_password"])) { When ever I read anyone's code or database schema and I see any mention of id, I immediately assume that I am dealing with a ...


1

As indicated by the scattered comments on https://stackoverflow.com/q/3349753/2943403, your approach is trustworthy. scandir() has an advantage over glob() (which is normally handy when trying to ignore . and ..) because glob() will not detect hidden files. The RecursiveIterator methods are powerful, but it is my opinion that fewer developers possess the ...


Top 50 recent answers are included