Questions tagged [php]
PHP is a widely-used, general-purpose scripting language that is especially suited for web development.
4,267 questions
2
votes
1
answer
112
views
Using a dynamic custom 404 template in Laravel
I have made a Laravel 8 blogging application that supports themes.
I had made a custom 404 template for every theme, the path to it being ...
7
votes
4
answers
651
views
CSV handling class
I'm a hobby coder at best. I know enough to make helpful programs to assist me with day to day life and work (mostly with PHP/JS, some C#). I'm wanting to learn more about good coding practices. I ...
3
votes
2
answers
162
views
Laravel Wallet Service Backend
I’ve built a backend-only wallet service using Laravel 8, and it’s fully containerized with Docker. The project handles two user roles (Players and Backoffice Agents) and provides JWT-based ...
2
votes
1
answer
89
views
Return breakdown of component from database into its constituent materials; correctly handle recursive scenarios
I’m working with a MySQL database that models product compositions and raw materials. There are two relevant tables with columns as shown:
product_recipes:
...
5
votes
2
answers
244
views
Laravel as client for Strava 3rd party API
I’m developing a Laravel app which acts as a client to consume a 3rd party Strava API. My app also functions as an API for a frontend SPA. The user (which is just me for the time being) will already ...
3
votes
1
answer
186
views
Rendering data from mutiple models using controller and send to a single view
I have a master page, where I need to render data from multiple models. I have made a prototype of that page to show only the required conditions.
What is the best approach for controller to retrieve ...
6
votes
3
answers
550
views
PHP PDO wrapper class with security
I have created following php PDO wrapper class with the help of google and other some websites and my little knowledge.
I will use this for less coding work without change whole previous coded ...
3
votes
1
answer
236
views
Image preview and delete for Laravel blog application
I am working on a blogging application in Laravel 8.
I have put together a way to preview and remove the main article image.
In the ArticleController.php controller,...
3
votes
1
answer
99
views
A function that returns correct number of inserted, updated and skipped rows for INSERT or UPDATE query
When MySQL executes a Data Modification Query, it provides some additional info on the outcome, which is usually displayed in the console. This info is also being exposed through MySQL C API and this ...
2
votes
2
answers
183
views
Convert binary string to text base64 [closed]
I have a dictionary with a lot of symbols, each of which is encoded in a huffman binary string.
Example:
Symbol
Huffman Code
you
010
shall
0111
not
00111
pass
00001
...
...
Therefore I encode the ...
3
votes
1
answer
71
views
PHP script to generate named CSS grid areas
I wrote this PHP script to dynamically generate a topic header layout using CSS grid. The $columns array defines each column’s properties—like its CSS class, size, ...
4
votes
2
answers
499
views
Improving upon the Security of my Export Remote Database to Local PHP API
I am working on an in-house application, and I am working on how our application communicates with our remote server.
I have a PHP script that acts as an API to call to our MySQL DB and dump its ...
3
votes
1
answer
69
views
Wordpress custom registration form with additional fields
I work on plugin for custom auth pages for WordPress and I try to create a custom registration form with additional fields. it has a shortcode in Beaver Builder. Is this the correct approach, and ...
4
votes
1
answer
176
views
Replace node type in Drupal
In Drupal 11 or greater, this code is used to change the node type of a node. How would you improve the code if at all?
...
5
votes
1
answer
559
views
User Management API
I got as task to build a simple Laravel API that should:
1 - Create User API
2 - Get Users API
So I run the artisan command to ...
2
votes
0
answers
56
views
SPA in Symfony UX Turbo
I am currently learning Symfony UX. My focus today was on UX Turbo. I basically wanted to create a very basic Single Page Application.
User can 'login' using a form, submitting the form should render ...
4
votes
1
answer
166
views
Creating Dedicated Database for database test cases (Tests that I need to check the data are written or read sucessfully) in phpunit
I am making a base test class that bootstraps database Test cases
...
4
votes
3
answers
1k
views
A function to convert numbers from scientific notation to plain decimal
When PHP converts a number to string (for printing it out, for example), sometimes it may convert it to scientific notation out of nowhere (0.000021 for example). Or the number can be already in a ...
0
votes
0
answers
52
views
Duplicating answers from a multi-section form populating multiple tables
I am implementing a system in which a client fills a form. Each form has multiple sections and each section populates multiple tables, thus user fills each section separately.
I was asked to make a ...
3
votes
1
answer
89
views
Rounding a decimal to the nearest (up or down) 50's integer
I need to round a decimal to the nearest 50's (please correct this phrase because I am not sure how it's called in English)
For example:
...
3
votes
2
answers
130
views
Sending Firebase Cloud Messaging Notifications via FCM HTTP v1 API with PHP
This is my first time using FCM, and I had a lot of trouble finding up to date examples on how to send notifications using Firebase Cloud Messaging Notifications via FCM HTTP v1 API with PHP. I'd ...
4
votes
4
answers
239
views
Reversing string in PHP
I got this task to evaluate my knowledges in PHP.
I was asked to avoid using functions like strrev() or array_reverse().
...
2
votes
0
answers
62
views
Testing PHP CodeIgniter 3 controller with PHPUnit
I want to unit test my PHP website, which uses the outdated framework CodeIgniter 3. CodeIgniter 3 uses the MVC pattern, and each page on the website corresponds to a public method in a controller.
I ...
3
votes
1
answer
209
views
Detect the social network of a given URL
I am making a class in PHP that detects the social network or instant messaging platform of a given URL:
...
2
votes
0
answers
106
views
comment-monk - Comment hosting script for static blogs and websites
So few days ago, I had created another review request for sqlite database schema for a comment hosting system.
Now that the app development is complete, I have pushed the initial version on github. As ...
3
votes
1
answer
58
views
Open Source Disposable Email Filter PHP Package
I’ve recently developed an open-source PHP package called Disposable Email Filter and would greatly appreciate a thorough code review. The purpose of this package is to filter out disposable email ...
2
votes
0
answers
130
views
Add a Custom Billing Field to WooCommerce Checkout, Order Meta, and User Meta
I have implemented a custom WooCommerce checkout field to collect a Tax Exempt Number in the billing section. This field's value is stored in the user meta upon checkout to facilitate future orders.
...
2
votes
1
answer
194
views
Count how many numbers in a range have exactly three divisors
The challenge
Given array a of n numbers, I need to count how many positive numbers less than each aᵢ have exactly 3 divisors.
Constraints
1 <= aᵢ <= 2.5 * 10¹³
In other words,
the minimum ...
4
votes
1
answer
152
views
Evaluating Extended Operating Hours Past Midnight Across Timezones in PHP
I am working on a project that involves tracking the operating hours of businesses across different timezones. Some of these businesses operate past midnight, and to accommodate this, operating hours ...
6
votes
3
answers
309
views
Simplified VarDumper in PHP
I wrote a simplified VarDumper and wanted to get feedback on areas I can improve on my code. My biggest area of concern is the captureContext method making sure I get the correct file and line ...
4
votes
1
answer
459
views
Get visitor current city via API or display the city the user searched for
I am writing a simple PHP script to display all my available stores in google map. If the user just came in, I need to set the user current city as default city using geolocation (3rd party); ...
2
votes
1
answer
161
views
Telegram YouTube upload video notification Bot
I made a simple script that notifies a Telegram Channel when a new youtube video is uploaded upon a YouTube channel:
index.php
...
4
votes
1
answer
239
views
Sending only modified data from a table to the backend as form data
The frontend has a table with hundreds of rows. Each row consists of different inputs (text, file, ...
3
votes
2
answers
266
views
Is showing an HTML file that the client uploads safe?
I have created two pages (one straight HTML, the other PHP) to show an HTML file in the context of my server. The reason for this is simply to get access to / the styles in the CSS spreadsheets - not ...
2
votes
0
answers
177
views
PHP Parser and converter - SOLID and DRY
I am working on a PHP application that transforms data from the input CSV (JSON, TXT, or XML) into an output CSV (JSON or database, for example).
The output format differs from the input: some columns ...
2
votes
1
answer
76
views
Justify Text on Image GD PHP
we are trying to justify a long text into a image and we need to justify it. We have solved the problem with this function, but it's too heavy and takes a long time to process the text justification. ...
3
votes
4
answers
783
views
Sanitize URL string for Insertion Upon DB table via Eloquent model
In my case I am saving a URL into my database via Eloquent Model:
...
2
votes
2
answers
116
views
Migrating configuration method
I have a legacy PHP project using a self-styled configuration file (named globals.inc.php) which is generated by build scripts based on a template included in the ...
1
vote
2
answers
251
views
PHP WordPress Code - Pricelist Template
I've been working on a WordPress pricing page template and would appreciate feedback on the code structure, organization, and any potential improvements. The template is used to display a pricing list ...
8
votes
3
answers
1k
views
A simple PHP login form with PDO
I wrote a simple PHP login form for a website. It has an initialization script, as well as a form to allow a user to login, plus a link to log the user out after logging in.
...
2
votes
1
answer
85
views
Rails session after migrate from PHP (improved)
previusly I make a post for Session Logic for User Verification in Rails Migration.
Now the improvement version following advice of the comments is here.
The problem was the use of `` for executing in ...
3
votes
1
answer
115
views
Session Logic for User Verification in Rails Migration
This is a logic to create sessions on RoR 7.1.2 based on the last version of the website which was in vanilla PHP, with the upgrade I have to deal with the users that were already signed up but not ...
2
votes
0
answers
209
views
Handling large amount of traits and properties in classes
I've got an open-source project that I've been working on for a while, and I'm looking for advice on handling large classes. It's a Laravel 10+ package for building forms, and everything works fine, ...
5
votes
2
answers
310
views
A PHP class for the common database operations?
I'm a CS undergrad, so I don't have much experience. But while coding vanilla PHP projects, I found that I was repeating myself a lot with the CRUD operations. So overtime, I developed a single file ...
5
votes
3
answers
1k
views
A very simple router for a PHP application
/.htaccess
ErrorDocument 404 /inc/index.php
ErrorDocument 500 /inc/index.php
RewriteEngine ON
RewriteRule ^([a-z_-]+)$ index.php?page=$1 [L]
/index.php
...
2
votes
1
answer
109
views
Production-Readiness Advice for Laravel/ PayPal Integration
I am currently working on integrating PayPal with my Laravel application, and it's my first time incorporating PayPal for production use. I have written the following code and would greatly appreciate ...
4
votes
2
answers
166
views
Apply placeholders to an array in a loop for pdo statements for search functions with unknown numbers of keywords
I'm a newbie to PHP and other programming for that matter.
I'm doing this simply to learn. Figured the code could be used to search through a police database or something.
The statements are Microsoft ...
3
votes
1
answer
124
views
Laravel seeder for email template settings
This is my Laravel seeder for two database tables. I need to make this seeder more efficient and optimized. How can this be achieved? I would appreciate some tips.
...
4
votes
2
answers
255
views
Querying for vendors and categories
I'm looking for pointers on the best way to optimize my code below. The query is designed to pull for a vendor database in a separate SQL server table that I built a connection to in my wordpress site....
4
votes
1
answer
170
views
PHP CSV Parser: Separation of concerns and SOLID principles
I implemented a CSV Parser with Separation of concerns and SOLID principles in mind.
Does that code match the principles?
Here a sample data (CSV):
...