Questions tagged [php]

PHP is a widely-used, general-purpose scripting language that is especially suited for web development.

Filter by
Sorted by
Tagged with
0
votes
0answers
20 views

How would you refactor code like this with multiple if-else if statement?

I have a class ParentIdResolver which returns the parent id of the product based on the type. The class looks like this: ...
-1
votes
0answers
10 views

Mastering PHP procedural style

I have been using PHP for a while now. I thought I had the basics already down pack but someone told me that I am not skilled or have enough knowledge yet. Does anyone know a good place to start over ...
3
votes
1answer
28 views

Read a csv file and insert into DB table

I've found some resources about PHP performance optimization here and there but I don't know how to start. I send 130k CSV rows in approximatively 7min. My script read CSV file and send ...
2
votes
1answer
47 views

Get all routes that start with rt_

The code reads all my routes and return to my AJAX request the names of the routes without duplicates and just those that have the "rt_" prefix. ...
1
vote
1answer
2k views

Fix line breaks, cross-platform

So I ran into an issue where a client sent me a sample file and the line breaks were not preserved when reading the file using PHP from linux. So I wrote up a little function that should hopefully fix ...
5
votes
2answers
165 views

Queries to get unpaid and unpaid invoices

Here is my code: ...
5
votes
3answers
230 views
+100

Class showing a format similar to var_dump RC5 Version

Some methods of this library require some improvements (see this description): In the constructor I am trying to create the possibility that the user modifies the ...
4
votes
4answers
931 views

Hacker rank - Left rotation - PHP code feedback

Here is the problem description - https://www.hackerrank.com/challenges/ctci-array-left-rotation/problem A left rotation operation on an array of size \$n\$ shifts each of the array's elements 1 ...
2
votes
0answers
23 views

Query WordPress database, returning an array of rows

This is one of my first attempts at querying the WordPress database for data, and some my first PHP code ever, so please bear that in mind when commenting. It is supposed find data between two dates, ...
-3
votes
0answers
21 views

Post request in React app to PHP file in Apache server on localhost [closed]

I am creating simple app for fetching icos and firm names from one site. I have this project already done with JQuery and now I am trying to learn React and do the same in it. First part of this ...
2
votes
1answer
17 views

Validator and Sanitizer for HTML 5 attribute regex according to current HTML living standard

According to https://html.spec.whatwg.org/multipage/syntax.html#attributes-2 an HTML 5 attribute name is defined like this: Attribute names must consist of one or more characters other than controls, ...
7
votes
3answers
156 views

Is my website's PHP registration system secure?

I would like to know if my registration system is secure. I'm not sure if it is secure, as I'm new in development, and I'm afraid that the system is flawed Also, I'm not experienced in object oriented ...
1
vote
1answer
178 views

Laravel show and update currency from rest api

I need: Daily save new exchange rates from the REST API in the database. Return the current exchange rate for a given currency, the whole table for a given day, the exchange rate for a given currency ...
-1
votes
0answers
35 views

Server-side form validation [closed]

I am validating a submitted form. My HTML code: ...
5
votes
1answer
44k views

Building a “LIKE” query in Yii2

This code makes an SQL query. The last andWhere() method adds a LIKE condition with one percentage sign at the right. I'm ...
6
votes
2answers
99 views

Password reset system in PHP

What I try to achieve I need to create a secure forgot password reset system. I am especially worrying about the security of this code and how to further improve it. Here's my code: ...
5
votes
4answers
1k views

Programming MySQLi prepared statements

I'm programming code with MySQLi prepared statements. I'm a beginner and just want to ask to experts if my code is correct. ...
3
votes
1answer
82 views

PHP: Simple SQL query builder

I've been lucky enough to get my first job as a junior PHP developer. I am concerned I'm not good enough. I would like to brush up on my coding skills and get as much constructive criticism as I can. ...
2
votes
2answers
224 views

Address class in PHP 7.4 with types

About this exercise I found out there is a form of strict types in PHP 7.4, so I freshened up my PHP coding with this simple Address class. I did not use PHP since ...
1
vote
2answers
62 views

Router and solid principle

I would like to know if my Routing system respects the solid principle ? The system is simple, Router class contains the routes and returns the correct route and Route class represents a route, ...
1
vote
1answer
41 views

Converting multi-dimensional array into row data

Input: ...
2
votes
0answers
240 views

PHP / Laravel - Using Python to image manipulation

I have a simple job class in Laravel, that: Get all the images in a folder /original Perform some image manipulation on each image Save each image in a new folder ...
0
votes
1answer
45 views

Switch statement decreases adaptability of a function

Below you can see a class and a function. The class is just an dummy entity. The functon has a switch statement. That switch statement calculates the tax by to a predefined hardcoded string, and I don'...
5
votes
6answers
13k views

PHP checking for array key or using default value

I currently use this code pattern fairly frequently ...
0
votes
0answers
13 views

Facebook Login with JS and validate with PHP - Secure?

I am using Facebook's Javascript SDK for the login, and I am validating it with PHP Graph SDK v5.x Here is the JS: ...
2
votes
1answer
50 views

REST API in clean PHP

I tried to create REST API in PHP because I would like to learn the basics before I will start use frameworks to create apps. I created a Model with CRUD methods which can be used in every model to ...
2
votes
1answer
59 views

Handling user sessions on website using $_COOKIE and $_SESSION

So I am building a website. It will be only used inside our small company and it's not made for public use. What I want to achieve is the ability for user to maintain session after sign in for a ...
6
votes
1answer
89 views

Basic login system with 2 factor authentication

What I try to achieve I need to create a administration-panel for a website. Therefore, I need a possibility to protect the content of the panel via a password. The functionality doesn't have to be ...
4
votes
3answers
103 views

PHP script that returns an error message based on what $_POST parameters are missing

I have a script that checks if the specified set of $_POST variables are supplied and not empty and returns an error string that is human readable. Here's my code: <...
2
votes
1answer
49 views

Upload Image From URL via PHP (In a safe way)

I'm trying to make a simple code to upload an image directly from a url. However I have concerns about the safety of my code since a user can submit any url. How I can make it more safe? All the good ...
1
vote
0answers
43 views

Using Reflection in Calling Method from URL parameters in MVC [closed]

Currently I am working on a simple MVC framework of mine. So my Core library loads the controller and method based on the URL with the given parameters. This happens in the following way: ...
-1
votes
2answers
91 views

My Script Inserts users into a database and hashes the password, I need to know how to prevent SQL injection with Procedural-Oriented MySQLi [closed]

My script works but I just want to know how I can protect myself from SQL injection with Procedural Oriented MySQLi. Most of the tutorials are about Object-Oriented MySQLi and I'm not familiar with it ...
3
votes
0answers
150 views

Codeigniter 3 loading models in a different way

I'm currently building an application that uses the same models in different controllers. Instead of using the normal way, being loading the model in the controller I've build a "core controller" (<...
3
votes
3answers
1k views

MVC design to fetch, store, and present data from an external source

A couple of weeks ago a company sent me this coding challenge: Please write a PHP web application and send it back to me as zip file: Which waits for a user action, like clicking buttons. According ...
4
votes
0answers
72 views

Enables markup to instantiate objects, call methods, and generate HTML

I created this package PXP. PXP enables markup to instantiate objects, call methods, and generate HTML. It works similar to a server-side templating engine, but rather than enforcing braces it ...
5
votes
1answer
2k views

php swiftmailer two message instances with one mailer instance?

I created a simple function for swiftmailer to send two different messages for support and client. Not sure i did it the rigth way as I am using two different instances for message and one mailer ...
2
votes
1answer
234 views

Prefixing prices of certain product categories with text in Woocommerce

I had the need to prefix the price for certain product categories on only the shop page (because the price can be higher depending on extras that the customer might want). These were my requirements ...
3
votes
1answer
61 views

What is the best way to use the database connection file in PHP?

I have a connection.php file into my root folder and at the bottom, I added BASE_URL ...
1
vote
1answer
33 views

JavaScript date format string to php date format string convert

Please find the following scenario, I've dynamic JS date format string from API but I am looking for the best way to convert the format that accepts in PHP date format. For now, I wrote it my own way ...
0
votes
2answers
64 views

Format simple array in multidimensional

I have a simple array in PHP like this : ...
2
votes
2answers
366 views

Present database results based on form submission

When we select the 'info' list in the select field, the article with type 'info' characteristic automatically showed up, and when we select 'Berita' list in the select field, the articles with type '...
5
votes
1answer
85 views

Naive php web hook endpoint for use in a production environment

Below is the WebHook endpoint in its entirety. I have five seconds to acknowledge if the payload is correctly formed. After that, the payload is inserted into a queue for processing. Importantly, it ...
2
votes
2answers
212 views

Read a text file and print pre-defined html when specific keywords are found

How can I code this in a better way, in one file? Output must be more than one (if there is more that one status_update with the given word "online or performancedegradation"), like: ...
2
votes
2answers
2k views

Search script for autocomplete suggestions

The following search script creates a JSON response for an autocomplete field. The tables and fields search from are flexible to allow using the same script for different type of searches - the idea ...
2
votes
5answers
186 views

Sort multidimensional array based on another one containing the desired order

I have an array like this: ...
1
vote
5answers
465 views

Sorting an array of jobs by various criteria

Below is my current code for sorting an array, "$jobs_list". It's not very DRY and it's fugly. And there are several more similar case statements still to go in. How could I write it so my brain ...
1
vote
3answers
124 views

Insert row into database using values from a html form submission

I have a comments page on my site and I was wondering if it is vulnerable to some sort of sql attack or something else. At the moment users can type what they want, they can even write a php script ...
2
votes
2answers
8k views

Sorting an array to match the order of values of another array

I'm running hundreds of curl operations in parallel to my own API, the response array that I get is out of order (the reason being that the first one to finish gets added to the response array first). ...

1
2 3 4 5
84