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
5
votes
2answers
151 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 ...
2
votes
0answers
10 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, ...
-2
votes
0answers
16 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 ...
1
vote
1answer
12 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, ...
6
votes
3answers
126 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
32 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
96 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
75 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
223 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
60 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
40 views

Converting multi-dimensional array into row data

Input: ...
2
votes
0answers
238 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
43 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
7answers
13k views

PHP checking for array key or using default value

I currently use this code pattern fairly frequently ...
0
votes
0answers
11 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
48 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
100 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
46 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
149 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
71 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
227 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
211 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
174 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). ...
2
votes
2answers
329 views

Sorting elements in array with a certain condition

This is what I have: function get_create returns a link with new filtered/sorted properties: Code on screenshot ...
0
votes
0answers
33 views

Server-side processing data table best and secure code using ajax

I am using PHP and Server-side processing data tables. I have more than 30k records on my table and I have to display the records on my page when reload so I used the below code. Is this code is the ...
0
votes
1answer
40 views

DateTime Extension for entering historical dates, i.e. birthdays

This class is intended to fulfill these requirements: Output in Y-m-d H:i:s format Allow dates to be entered as m-d-Y or m-d-y Complain if an invalid birthdate is entered (i.e., in the future or ...
7
votes
2answers
23k views

groupArray() - Convert flat array into multidimensional array by group

I've recently written a function that allows me to take a flat array and convert it into a multidimensional array by a specific key in the array. ...
10
votes
3answers
1k views

IP address detection code

I am using PHP for detecting a user's IP address and displaying their details, and I use OOP (i.e. object-oriented programming). Are there any problems in it or is it well-written? index.php: ...
5
votes
2answers
85 views

Mysql PDO Wrapper that throws Unique Constraint Exception

The main reasoning behind this PDO wrapper, is that I find myself using unique constraints quite frequently in my designs, and I have ...
1
vote
1answer
61 views

Reduce database touches for one to many data pull

I have the following function which works properly and returns all of the rows from a specific table, then loops through each row to add data related to it as a subarray. ...

1
2 3 4 5
84