Questions tagged [php]
PHP is a widely-used, general-purpose scripting language that is especially suited for web development.
4,303
questions
-2
votes
1
answer
56
views
Preventing PHP SQL injection on login [closed]
I had a login code like this:
...
0
votes
1
answer
38
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,...
2
votes
1
answer
70
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 ...
0
votes
1
answer
60
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 ...
5
votes
2
answers
174
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, ...
0
votes
0
answers
25
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
...
1
vote
1
answer
27
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 ...
2
votes
2
answers
85
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 <...
1
vote
1
answer
50
views
Laravel Eager Loading tickets from DB
So I have the following relationship in my Model:
Events Model:
...
5
votes
2
answers
107
views
Sorting an array by given hierarchy
I have a known hierarchy of the organization units, by descending order:
...
1
vote
0
answers
79
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 ...
1
vote
1
answer
93
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 ...
3
votes
1
answer
115
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 ...
2
votes
1
answer
124
views
Generator for colors
The goal here is to pull an item from an array and when the array ends - to start over - and allow you to pull items infinitely as needed. We don't use PHP that much, so please let us know how we can ...
2
votes
2
answers
124
views
Route protection with custom middleware in Laravel 8
I am working on a blogging application in Laravel 8.
The application assigns users roles and permissions. There is a many-to-many relationship between roles and permissions.
I have created a custom ...
-1
votes
1
answer
57
views
Securely store password in database and then show it on demand? [closed]
I have written a small password manager script for my own purposes. It is hosted locally and cannot be accessed outside my local network. You can see the code on GutHub
I know it is better to encrypt ...
3
votes
2
answers
92
views
PHP Router For MVC with strict routing requirements
I had previously asked the question here.
The response was pretty much "wow this is bad".
So I learned everything I could and wrote what I believe to be better using TDD.
The strict ...
3
votes
1
answer
391
views
Setting default of <options> in Laravel with PHP Match
I have a filter component that lets a user filter for events on a website. The user needs to see what category is currently selected in the filter. So I have an URL with parameters.
e.g. ...
2
votes
1
answer
86
views
PHP Bootstrap Autoloader
I wrote an PHP Autoloader to include it "easyer" to my projects.
Here the folder structure:
...
-1
votes
0
answers
70
views
Eager loading using microservices
I am not quite sure if this is the best approach when fetching relationships, I have this:
LinkController.php
...
0
votes
2
answers
59
views
Configuring SQLite3 for best efficiency as a persistent cache
I'm using SQLite3, via php's extension module, to create a persistent object cache for WordPress. It's intended for use on modestly sized sites that don't have access to redis or memcached. Why use ...
2
votes
1
answer
154
views
C/C++ hash looking in flat database compared to PHP
I have a hash table which I would like to query as fast as possible.
The hash table is stored this way :
When I query a hash, I extract first 4 characters then use it to find the file. For instance a ...
2
votes
4
answers
452
views
Creating storage path for file from first characters of a hash
I made the following function to create the storage path for files from the the first 5 characters of the file's hash:
...
5
votes
2
answers
914
views
Formatting Credit card names from API response
I have an API that returns the brand of a credit card. I want to make them look nice for my user (e.g. correct case and spacing). The possible options are amex, <...
3
votes
2
answers
86
views
First attempt at a distance object
In our code we deal with distances a lot, a distance being a number and unit
eg 15km, or 1.234mi
The current approach is to use 2 functions, convert_distance(), and ...
2
votes
2
answers
67
views
delete multidimentional array value in php
I made a program that converts JSON to a PHP array and checks every value of the multidimensional array with a loop and if a value matches certain values then it deletes that key and value and ...
1
vote
2
answers
90
views
PHP function that checks if user should have access based on button click and yearly quarter
I have a function that has a few and/or operators in it. I'm sure there is a better way to write this but can't seem to figure it out. I thought I could use arrays but ran into an issue with having ...
0
votes
0
answers
248
views
Pay with PayPal through cURL and verify
As All PayPal PHP SDK deprecated, I wrote a simple PHP class to make payment with PayPal through cURL and verifying it. Note :
I didn't add shipment details for payment because didn't need that.
For ...
2
votes
1
answer
103
views
PHP Laravel Check if given date is a week or a regular day
I have a problem. In my project the user can copy a menu for a specific day or for a specific week. The value that will be sent to the back-end will be something like:
...
2
votes
1
answer
98
views
Extracting authors and books from XML and inserting them into PostgreSQL
There is a tree of start folder, it's subfolders, their subfolders, etc. In each folder, subfolder, etc. there are the same structured XML files stored.
books.xml
...
6
votes
2
answers
248
views
PHP readfile() with 304 Not Modified and HTTP 206 Partial Content support: httpreadfile
I wanted a readfile with 304 Not Modified and 206 Partial Content support, I think i got right, but probably spent way more effort on error-checking than worthwhile.. Also I didn't develop it by ...
1
vote
0
answers
31
views
How do you decide if a function should return data directly (via return statement) or indirectly (e.g. updating a class property) or both? [closed]
I have some functions which update records in some database tables.
When I run each function I want to know the number of records affected by each.
I'm wondering what the most elegant way of returning ...
1
vote
0
answers
41
views
PHP PDO prepared statement with IN [closed]
Here's my code:
...
0
votes
1
answer
92
views
Can I use PDO transaction in this way? [closed]
So I want to use PDO transaction in PHP OOP where in the class are multiple insert/update queries.
If I create a new methods in Class like beginTransaction(), commit(), rollback() and I use them ...
8
votes
1
answer
191
views
Convert integer to Roman numeral string
This is my 1st time developing PHP code and I am only 13 years old. I have experience in other programming languages like lua, python, and c++.
This is a simple Number to Roman Numeral code I made for ...
3
votes
3
answers
458
views
Sort array of associative arrays by the key of the subarrays
I am trying to sort an array of associative arrays in reverse order by the key of the subarrays.
I solved it with a bubble sort algorithm which worked just fine in my test.
I was wondering if there is ...
1
vote
2
answers
109
views
Laravel PostController
I'm new at Laravel and I got an assessment task from company where they want me to create a mini-blog with Users and Posts.
I was using following methods:
index, create, show, store, edit and destroy ...
0
votes
1
answer
59
views
Default to array when value is null or false
I'm working with ACF in WP which provides a get_field() function. The function can return an array of values, null or false. ...
0
votes
1
answer
190
views
Index.php automatic router for custom MVC
In house we have been building our own MVC framework. One of the things that was important in the project was to not have to add routes manually but instead have a standard and let the index ...
2
votes
2
answers
657
views
Saving form data to a text file on server
I want to save simple string data as a simple text file (.txt) on the server (together with the IP), but I cannot find any clear guideline on how to do this correctly/efficiently/safely. (Maybe I'm ...
4
votes
3
answers
358
views
Queries to get products selected in multiple stores
Project description
I'm making a website listing products. The listing goes as following (See here):
Product name
Shop name
Price in that shop
If the product appears multiple times in the table for ...
0
votes
0
answers
191
views
Drag and Drop Sortable Image Upload System
I am working on web page where I want to use a "drag and drop" image upload system, with options to remove and sort images before upload.
I would like to ask your opinion whether this system ...
2
votes
1
answer
117
views
function to group data by parent branches
I wrote this function to take database output like from PDO's fetchAll(PDO::FETCH_ASSOC) and turn it into a tree. For small datasets it works well. However, when ...
4
votes
4
answers
456
views
Functions in PHP to run basic MySQL crud
I wrote a list of functions in PHP that I want to use in my pet project as an autoloaded file for all parts of the app. The purpose of these function is to shorten the code you write for MySQL queries ...
3
votes
1
answer
237
views
Generating responsive image html with php?
As a beginner in php, I welcome you feedback on improving or simplifying the following php code that generates this responsive image html (image sizes and formats are auto-generated using Gulp). For ...
1
vote
2
answers
242
views
Laravel 8 blogging application
I am working on a blogging application in Laravel 8.
In the FrontendController controller I have:
...
1
vote
0
answers
141
views
Applying the Strategy pattern for payment methods
The strategy pattern is applied in the code below in the payment separation solution. Please evaluate if it is well done according to standards. I would be very grateful for suggestions.
...
0
votes
0
answers
46
views
file MIME check on update form
I'm a very beginner. I developed this today and it's working (YAY) but I would like to make sure ALL of my checkFile($file) method's conditions are fully used and ...
1
vote
0
answers
118
views
Error handling for Laravel REST API client and server using bearer token authentication
I would like to query a REST API (which uses Bearer token authentication), handling several exceptions that might occur. Could you tell me if the following code (which I explain later in this post) is ...
4
votes
3
answers
828
views
Filter an array, but remove the filtered elements
I needed a PHP function that would filter values from one array into a new one, while also removing those values from the original array. After looking through the docs, I didn't see any such function,...