Questions tagged [php]
PHP is a widely-used, general-purpose scripting language that is especially suited for web development.
4,336
questions
0
votes
0
answers
19
views
Execute a sequence of instructions
I wrote a quick POC application to execute a sequence of defined instructions and I would like some feedback if possible.
This is purely a proof of concept and I wanted to implement a concept similar ...
0
votes
1
answer
16
views
Sudoku puzzle solver for Leetcode
I just solved a problem from leetcode that is faster than 28.42% of the PHP codes, so the main review target is not the performance or alternative ways to solve this problem. I wrote the code thinking ...
-1
votes
0
answers
26
views
use an attribute of another class in a class (corresponding to the foreign key) [closed]
I have created two tables, one corresponding to a book (id book primary key, title and availability (boolean)) and to a borrower (id borrower primary key, name, borrowed or not (boolean), and id book ...
0
votes
0
answers
62
views
Vanilla JavaScript Email Obfuscation Defenses Against Bots [closed]
I have been using Cloudflare's Email Obfuscation for a while now but the JavaScript file loaded was causing a pretty substantial increases in Total Blocking Time and Time to Interactive. Then after ...
-2
votes
1
answer
47
views
Insert row into database using static or non-static method [closed]
I would like to know if there are any benefits of one of the following 2 methods which insert an object into a database
The first function calls the Model method statically, creating a new instance of ...
-3
votes
0
answers
45
views
how to make the code more beautiful and correct? [closed]
Hi everyone i trying myself with php+ base oop sintax. So can you tell me what I need to change in this code to make it more beautiful and correct
index.php
...
1
vote
0
answers
47
views
php login system - how to make the login part better? [closed]
learned from a tutorial how to build it, but modified it's login part to fit me.
but, I'm not so sure it's the best login so I want to know how can I make it better.
the code:
index.php
...
0
votes
2
answers
47
views
Algorithm for twoSum
This is my PHP algorithm for the twoSum problem in leetCode:
...
3
votes
2
answers
106
views
Cryptographically secure version of the core array_rand() function
I want a cryptographically secure version of array_rand(). Is this it?
...
0
votes
1
answer
62
views
Verifying user login status
When a user logs in, I save a token (hashed password) to the user's folder on the server and send the token also to the app which is saved in localStorage.
I need to check if the user's login token ...
0
votes
2
answers
153
views
Version 2: Display visitor's number on your web page (changed code after getting answer for first version)
Version 2: Display visitor's number on your web page (changed code after getting answer for first version).
The first version is here: Display visitor's number on your web page
The "visitors&...
0
votes
1
answer
97
views
Display visitor's number on your web page
Display visitor's number on your web page.
The "visitors" table has only one column (visitor_count) and only one row. The column's initial value is 0.
I know goto should not be used but then ...
2
votes
1
answer
67
views
Proper PDO connection function
I am reviewing the database class for a live website. I am not sure if the current connect function is the best way to create a pdo object as it appears to create a new connection every time it is ...
0
votes
1
answer
34
views
Laravel controller getting results based on parameter including relationship results
I am trying to learn to improve my coding on a daily basis and this is one of the first times I am posting on here, so bear with me.
I have two models, a Payment and an Expense model. A ...
1
vote
1
answer
95
views
Optimization of laravel pivot table relationship
I have a pivot table called invite_riskarea which is designed as follows:
This table handle the permissions that have a specific user (through an invite id) to ...
1
vote
1
answer
59
views
Updating multiple database tables when products are shipped back by customer
So, in this example I have to make these changes in my tables:
Select Product Data => SKU, QTY
Insert into shipping_back table
Update in shipping_back to current date
Update in customers to ...
1
vote
0
answers
131
views
deprecated strftime in PHP 8.1
I saw that strftime is deprecated in PHP 8.1.
I saw I can use a class include in intl but I'm not sure to understand how to use It.
On my site I use this function with the array $datesToConvert{020222,...
1
vote
1
answer
38
views
PHP autoloader that uses array of file paths
After doing much reading of the PHP docs and trying out other developers' autoloader code, below is what I've come up with for an autoloader. It is working as expected so far. Posting the code here ...
0
votes
0
answers
45
views
Image file uploader webpage in HTML5 and PHP
I am trying to make a webpage for uploading image file and storing the uploaded file on server. There are several features in this implementation:
There is a drag & drop zone on the webpage. You ...
0
votes
0
answers
50
views
PayPal payment logic in AJAX/PHP/Laravel
I've just finished setting up the PayPal checkout integration for my Laravel web app. It successfully processes a transaction and persists it in my database, and I want to make sure something as ...
3
votes
2
answers
145
views
Modify a WordPress loop to show posts of certain categories, based on user roles
I've got some code that works as intended, but I have a feeling that it's messy. This code is modifying a wordpress loop and the goal is to check the roles of the current user and show posts of ...
0
votes
1
answer
62
views
Authenticate and login script updated
How can I improve/secure my login script and how to check for any possible injection?
PS. the script must run on multiple platforms, so I need empty arrays for cases such as the Android ones.
UPDATES
...
0
votes
1
answer
42
views
Authenticate and login script
How can I improve/secure my login script and how to check for any possible injection?
PS. the script must run on multiple platforms, so I need empty arrays for cases such as the Android ones.
...
1
vote
2
answers
59
views
Having trouble deleting multiple queries (PHP, MYSQL)
I'm having trouble making WHERE IN query work, I was only able to make it work as a foreach loop.
My payload looks like this:
sku[]: BOOK0002
sku[]: BOOK0003
My ...
1
vote
1
answer
32
views
Regex to capture possible US date entries
The Problem
I'm relying on plaintext entry to capture dates.
End users are urged to enter as MM-DD-YY, but it'll be great to account for as many possibilities.
US ...
-1
votes
1
answer
78
views
Refactoring this code into OOP & less functional programming
I got feedback from an interview test where they wanted me to prove that I've got a grasp of OOP php programming. This file especially I got feedback on that it's more functional than it is Object-...
1
vote
1
answer
116
views
Authenticate and log in users
How can I improve my login script and how to check for any possible injection?
PS. the script must run on multiple platforms, so I need empty arrays for cases such as the Android ones.
user_table:
<...
2
votes
1
answer
79
views
array_reduce() for calculating totals
Below is a snippet that uses array_reduce() to calculate totals from a detailed dataset. The data shown is representative of a larger dataset.
This code outputs ...
2
votes
1
answer
40
views
Retrieve config values using custom helper
I've stored a set of theme related configuration in a config file.
config/theme.php
...
3
votes
3
answers
183
views
Regex to extract portions of string about shipment
The Problem
I'll be extracting up to 4 parts of a String that come from user-input.
All 4 parts need to be in order i.e. (1-4) below in that order
The first capturing group is required and the last ...
0
votes
1
answer
74
views
Upgrade security and code quality of a website contact form
I have a simple website contact form created back in 2017.
The form was developed using PHP, PHPMailer, jQuery, HTML and CSS.
I would like to make sure the code is up to modern standards and secure.
I ...
1
vote
1
answer
31
views
0
votes
0
answers
42
views
Using configuration file to store classes
I'm using a configuration file to store tailwindcss classes. The idea is to make a dynamic component and simply call the class from configuration file base prop call on a component. eg:
in config/...
0
votes
1
answer
42
views
Search controller logic to search through models and manufacturers
I have the following Laravel controller that searches through two models - Manufacturer and SearchTerm (which contains models of manufacturers, synonyms of models as well as common misspellings) using ...
1
vote
1
answer
41
views
User controller with method to display user profiles
I have few questions. Sorry if title is not a good fit. I could not think of a good one. I have read online about maintainability and elegance of the code. I have also seen few examples of DRY ...
2
votes
2
answers
134
views
Is this a good way to process an order? (SQL+PHP)
I'm making a simple webshop, it's not the full code, there are more security procedures. I'm just want to know your opinions. Thank you.
These SQL tables I have:
(I have more column in this table this ...
4
votes
2
answers
61
views
using PHP and JS to fetch data for an entry
I need to fetch some data from a mysql database. For that I created get_data.php on the server and a js function to retrieve that data on the client. Is this the proper way to do it? What would you ...
0
votes
1
answer
133
views
Is this session manager secure?
I'm looking for best practices for writing secure session managers.
I'm making a table for the authorization token (UUID OR GUIDv4) with autoincrement, user_id, token, status (enum) then update status ...
0
votes
0
answers
65
views
Validate avatar image
I want to know if that code is correct and readable. In class avatar, I make validation. I check if the field is not empty and if the photo extension is correct. If not, an appropriate exception is to ...
1
vote
2
answers
73
views
Optimize PHP code for Wordpress shortcode (Star-Rating)
I am using WP with the Avada theme and the built in Star Rating element as well as ACF Pro.
Unfortunately I found out that the Star-Rating element adds a rating scheme to the footer of the website ...
0
votes
3
answers
72
views
table name column name from GET parameter
This is a function that reads a setting data from DB.
...
0
votes
2
answers
73
views
Security of my upload script #2
I recently asked this question and got a response. I made improvements, it now checks if the file is an image and/or used UUID to store the images, and now I want to see if it's good or not.
How ...
2
votes
1
answer
113
views
PHP OOP: Configuring MySQL DB & query w/ Twig
I decided to up my PHP game and learn some OOP.
I am re-building my website from procedural to OOP, but since I don't want to use a full framework I fiddle with some components.
As a router I use ...
1
vote
1
answer
25
views
implode on two level dimensions array
I have an array like this
...
0
votes
0
answers
29
views
Update database records on data model change
Worker.php
...
0
votes
0
answers
58
views
Creating employee attendance report for some time period
I have written a logic which will get 2 months and get all months between them then I am looping all months and inside every month I am finding all days in that month then looping through these days. ...
3
votes
1
answer
44
views
a php function to check a 'deep' array value
I've just coded a little function to check and get a deep array value. Basically, I need to return the value or null if it's not set or does not exists, or in general not useful for databases records. ...
0
votes
3
answers
85
views
url encoding and storing (JS, PHP, MySQL) [closed]
This question is about how best to encode, send and store information between JavaScript, PHP, and MySQL
I am doing a GET request from HTML/JavaScript to my PHP server, which is then storing the data ...
2
votes
1
answer
66
views
PHP code that chooses between multiple HTML banners
In the snippet below, I'm creating a banner for my website. If I change the variable in the html file, I want to call a different banner. It does work as is.
...
4
votes
2
answers
361
views
Optimization of a Laravel controller that passes data and views
I am trying to build a website that shows events. And I use the following controller.
Please note that the urls ($view and ...