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
-4 votes
0 answers
25 views

Condition not correct? [closed]

I am using Joomla 5. In Joomla you can create articles and also show a summary of an article on a category page. For SEO reasons I want to use an alternative title sometimes on the category page. I ...
Louis's user avatar
  • 45
0 votes
0 answers
37 views

PHP implementing Dependency Injection

I'm trying to implement Dependency Injection in one of my projects. It's a project that when I started I didn't had much experience with sotware development, but now I feel like it's time to do a bit ...
CelsomTrindade's user avatar
1 vote
0 answers
38 views

Laravel seed optimize

This is my laravel seed for two table. I need an efficient and optimized way for this seeder. How can i make it efficient and standard. Give me some tips. ...
Tarikul's user avatar
  • 11
4 votes
2 answers
211 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....
Mike Mann's user avatar
  • 141
-1 votes
0 answers
130 views

Algorithm to create optimized regex alternations

This code creates optimized regex alternations from an input array using a trie: ...
live627's user avatar
  • 99
2 votes
1 answer
102 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): ...
dev-chicco's user avatar
1 vote
0 answers
44 views

Force free shipping for WooCommerce Subscription recurring orders only

I'm using WooCommerce Subscriptions and here's what I want to do: Use free shipping for all recurring orders even if the minimum isn’t met. Get rid of any other free shipping choices (like free ...
David's user avatar
  • 11
0 votes
1 answer
165 views

WordPress Plugin for WebP/AVIF Image Conversion

I'm looking for feedback on a WordPress plugin I developed for automatically converting images to WebP and AVIF formats. The goal is to optimize image loading performance. The plugin has the following ...
KermitTheFrog's user avatar
2 votes
2 answers
96 views

Four functions to measure and compare months of duration from one or two dates

I decided to write a few related examples of code, and honestly I don't know if I am overthinking, or just trying to find what is that right way to write functions and how to use them, so that ...
Erasus's user avatar
  • 240
0 votes
1 answer
66 views

PHP login codes suggestions

Now i have a fully functional PHP codes for login and registeration i was wondering if anyone could offer improvements to the code The code: Config.php: ...
Bebo's user avatar
  • 39
1 vote
1 answer
138 views

Follow up to Validation Script in PHP

So I've implemented the suggestions in Original question And now my code looks like this: ...
Bebo's user avatar
  • 39
1 vote
1 answer
100 views

PHP Validation script

The code below is modified slightly from the code in this previous post. I believe the code below could be improved and more secured but i don't know how so someone please show me how an improved ...
Bebo's user avatar
  • 39
5 votes
2 answers
353 views

Parsing gateway ip from `/proc/net/route` in a docker container

In try to replicate the outcome of the following command sequence using php: netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10 I did this using ...
Dimitrios Desyllas's user avatar
0 votes
1 answer
185 views

SQL & PHP login method

My code is working however it seems to be using old outdated php version so less secure and I'm still new to programming so I'd be more than thankful if someone shows me how an improved updated and ...
Bebo's user avatar
  • 39
0 votes
1 answer
87 views

Validating an input in a chatbot

Is this a good approach for validating user input in a chatbot? I am writing an autoposter telegram bot in PHP using the php-telegram-bot library (by Longman). I have a Task class that stores ...
Gigoshkin's user avatar
2 votes
2 answers
149 views

Best Practices for PHP PDO Pagination with Search Functionality

I'm working on implementing a pagination system with search functionality using PHP and PDO. The code I've written seems to work, but I want to ensure that I'm following best practices and avoiding ...
user275476's user avatar
4 votes
3 answers
1k views

Count unique visitor using IP address and make sure that 24 hours has passed before incrementing the counter

I've created a unique page counter using a PHP script. Pages could be videos, images, publications, etc. Every time a new user views a page, I record the entry and increment the view counter. I cannot ...
Marco's user avatar
  • 229
0 votes
1 answer
93 views

Implentation of Data Access Object Pattern

I'm tried to implement the Data Access Object Pattern. I have a base abstract class that is then extended for a specific table. I tried following some guides, but couldn't find a lot of info on this ...
NicholasJohn16's user avatar
0 votes
1 answer
82 views

List of URLs to "convert" to other URLs

I have certain URLs which I want to convert to another, for example, anything that starts with /some/url/: /some/url/a/b/, ...
pileup's user avatar
  • 361
1 vote
2 answers
240 views

How can I make my image upload more secure?

I gathered a lot of information in order to try to make my code as secure as possible, and I would like to know what I can do to improve more its security. (Sorry for my english if it's bad) What did ...
gabriel's user avatar
  • 13
0 votes
2 answers
111 views

Is overloading a database object a bad practice?

I created the below class as a convenient way to create instances of PDO that I then inject into the classes that need access to my database. Instead of doing ...
NicholasJohn16's user avatar
1 vote
1 answer
32 views

Woocommerce send unique pdf

I have developed a code to send tickets (PDF files) of a specific product in the order confirmation. I place the PDFs in a folder (i.e. Tickets) on the server after the purchase is completed. The code ...
user274953's user avatar
0 votes
2 answers
107 views

jQuery + PHP Form Submit and Refresh

Code below successfully processes and submits data to database. Is there anything else that needs to be included / considered? PHP (note-process.php): ...
Matt's user avatar
  • 9
3 votes
1 answer
166 views

PHP MySQLi Wrapper Class For API

I've never had my code reviewed before, so I am taking this opportunity to see what can be improved with my coding style. I am still somewhat "new" to PHP, in the sense that I'm an old dog ...
Bellator's user avatar
  • 131
1 vote
2 answers
176 views

Boolean Value Object

Purpose: I want to accept the value of a checkbox or database field and make a Value Object out of it. The input could be any of y, Y, n, N, Yes, No, yes, no, 1, 0, true, false, or NULL. In the case ...
Tim Morton's user avatar
0 votes
1 answer
80 views

PHP Class to render HTML div styled tables v2 [reviewed by me]

After my previous question I made several changes and came up with this. Remember: I wrote this for PHP 7.0.33. I'm aware I should upgrade, save the advice :) ...
julio's user avatar
  • 199
0 votes
1 answer
101 views

PHP pagination function

After reviewing my previous question I came up with this pagination function. On my first approach I wrote a class thinking about IDE's code assist and the review wasn't positive. In this function I ...
julio's user avatar
  • 199
2 votes
1 answer
279 views

PHP Class to render HTML div styled tables v1

This class aims to render an HTML compliant div styled table. I added a help() method that provides usage and styling in a more user-friendly way. Besides the ...
julio's user avatar
  • 199
2 votes
1 answer
121 views

php tmpdir() alternative to tmpfile()

tmpfile() creates a temporary file which is automatically deleted when php exit. I wanted the same for directories, came up with: ...
hanshenrik's user avatar
2 votes
1 answer
99 views

HTML form Class

After my previous question I revised the code to the code below. I am using PHP 7.0.33 and tried to accomplish PSR-12 as much as I could. In "condensed usage" in the docblock you can find a ...
julio's user avatar
  • 199
1 vote
0 answers
23 views

Use API data to ensure current product prices in database data then sort by price

Because I've waited until now to bother learning the magical JSON functions that modern MYSQL affords, I wonder if my code is optimally written and if there are cautions/limitations to be aware of. My ...
mickmackusa's user avatar
  • 8,544
3 votes
2 answers
579 views

PHP HTML form Class - so far so good?

I am writing this class to render HTML forms. It is working as expected, so far. There are many things to be done yet (including testing). Is it ok to keep this way? ...
julio's user avatar
  • 199
6 votes
3 answers
565 views

Recursive function for creating a cookies string

I've created the following function that creates a cookie string for passing to cURL. It can take a nested array or object of key-value pairs. It can either create nested cookie values as JSON, or ...
Jodes's user avatar
  • 340
0 votes
1 answer
87 views

Is there any sugestions how to make this script faster if its possible?

I wrote a script that uses an uploaded excel file to import data to the database. It checks for the image first if it can be downloaded without any error then insert the rest of the data. With ten or ...
Benjji's user avatar
  • 1
2 votes
1 answer
88 views

PHP Pagination class (Clase para paginar resultados)

This is my first question in Code Review. I apologize in advance for using Spanish (my native language). I thought there was a spanish version of Code Review. This class is meant for pagination. It ...
julio's user avatar
  • 199
2 votes
1 answer
60 views

Creating multiple conditions in objects preventing nesting

My class is a factory-method that allows to instantiate it only when the parameter $type (string) is "regular or premium" and when parameter $months (integer) is lower than 6. If $months is ...
Ricardo Castañeda's user avatar
-2 votes
1 answer
77 views

Preventing PHP SQL injection on login [closed]

I had a login code like this: ...
Bazim's user avatar
  • 19
0 votes
1 answer
138 views

php flock with timeout (for LOCK_SH / LOCK_EX )

i want a flock with timeout, unfortunately i haven't found a good way to implement it (like a signaled timeout on an actual blocking request?), so i'm just trying and sleeping until success or timeout,...
hanshenrik's user avatar
3 votes
1 answer
139 views

Calculate cost of standard or express delivery

I've got the following code, which calculates net delivery cost to 4 decimal places. Delivery can be either standard or express shipping. It is intended to return a string in 4 decimal places of the ...
Jonathan Clark's user avatar
0 votes
1 answer
72 views

GPG class for AJAX calls

I want to know if this GPG class in PHP is up to snuff as a professional-level class. I did my best to include everything and make it easy to use. I'm calling the object by invoke(). If anyone can ...
Anthony Pulse's user avatar
4 votes
1 answer
414 views

Update specific model attributes from a request

Background This is for an API and I'd like to use this Upsert action to take data from a request and only update the requested fields. I.e. These are partial updates and I will not update every field ...
Taintedmedialtd's user avatar
5 votes
2 answers
285 views

PHP Fisher-Yates shuffle with random_int

The PHP manual states that the regular shuffle() function isn't cryptographically secure, but that random_int() is. I thought, ...
James G.'s user avatar
0 votes
0 answers
71 views

Github API based backend using Laravel

I just created a Github API based backend, this api retrieves and stores information from the github users api app/Http/Controllers/GitController.php ,I am using Requests, Actions and services ...
DeveloperX's user avatar
1 vote
1 answer
293 views

Three way Eloquent relationship definition and saving in Laravel

I'm building a Laravel app (with Vue3 and InertiaJS), and I'm attempting to create relationships between three models: User Area WorkHours where WorkHours is the ...
wonder95's user avatar
  • 111
2 votes
2 answers
176 views

Laravel Event Filtering Controller

So I am currently writing a function in laravel that handles URL parameter filters. How the code works: So we have the following two URL parameters: timeframe and <...
Nifty Matrix's user avatar
1 vote
1 answer
86 views

Laravel Eager Loading tickets from DB

So I have the following relationship in my Model: Events Model: ...
Nifty Matrix's user avatar
5 votes
2 answers
1k views

Sorting an array by given hierarchy

I have a known hierarchy of the organization units, by descending order: ...
pileup's user avatar
  • 361
1 vote
0 answers
353 views

Select product variations using buttons/swatches instead of a dropdown

In WooCommerce, by default interface, selecting product variations is possible through a dropdown. But, I am developing a site where I wanted buttons/swatches instead of the dropdown. I achieved that ...
Chotu Kaalia's user avatar
1 vote
1 answer
110 views

Theme picker for Laravel 8 blogging application

I am working on a blogging application in Laravel 8. The application supports themes. In a nutshell, theme support works like this: In the views directory, I have ...
Razvan Zamfir's user avatar
3 votes
1 answer
356 views

Multi step form onboarding with sessions and cookies using PHP

My goal is to create a really seamless multi step form for onboarding with only PHP. It stores in sessions and cookies, and retrieves the session data from the cookie if it is stored. This is what I ...
tony's user avatar
  • 329

1
2 3 4 5
86