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

A create gateway controller in Laravel

In my app users can create and soft-delete gateways something like Paypal. Users of a website can connect to the gateway and make payments. I've written the logic in a transaction also locking a ...
1
vote
0answers
71 views

Serve rescaled jpg images on demand with myphoto!500.jpg syntax (here 500px-width rescaled)

On web pages, obviously we cannot serve 4000x4000px photos and just let CSS do the resizing: it would be too slow for end users and too bandwidth-consuming for the server. So it's important to rescale ...
4
votes
3answers
268 views

Passky Password Manager router with authentication and validation guards

I have a long switch statement and it would be great if someone know how to make it cleaner. Code is available on Github: https://github.com/Rabbit-Company/Passky-Server/blob/main/php/index.php And ...
0
votes
0answers
38 views

Choose meals for a week

I've built this complex form or at least what I would consider a complex form and it feels really dirty. It felt dirty while I was programming it but I wanted to get it working and then go back and ...
3
votes
4answers
431 views

Generate HTML select tag and options using a text file having list of countries

The code below will generate an HTML select tag and options using a text file having list of countries. If the file doesn't exist or contains only empty / white space lines then generate an input box ...
0
votes
0answers
18 views

Wordpress Custom Block that sources files from the theme images directory

The Goal Current PHP version 7.3.5 The block will have a function that sources a defined set of illustrations that are stored in {themeName}/images/illustrations. ...
0
votes
0answers
57 views

query data from mapping name but use many memory

In my class the constructor queries data from the database. In the database there is a table containing more than 400k records. After the query I tested memory size- it uses more than 10m++ bytes. so ...
10
votes
2answers
2k views

Is my PHP login system following best practices? Is the code really OOP?

I'm learning about OOP and putting my knowledge into practice. I created a login system in PHP, so I wish someone could tell me if I'm on the right track. I feel like I'm getting better at coding, but ...
2
votes
1answer
51 views

Handling Medium-like text editor output at backend

I'm a developer who has completed almost one year of full-stack development & learning. I published my very first package lately, and I don't know is my code good or bad. So I jumped down here. ...
0
votes
0answers
22 views

Recreating WP Columns Block - Columns Container Only

I have been working on recreating the WP columns block using server-side rendered blocks. For the base creation of the block structure, I have used ...
0
votes
1answer
43 views

PHP search multiple filter inputs

Okay so I built this search page that searches for posts but my current code seems so bloated and inefficient. My script(search page) ...
2
votes
2answers
59 views

remove ALL duplicate elements from an array

I have this code to remove duplicates (all occurrences) from an associative array, does PHP have methods to do this ? Or is there a way to improve the code ? I looked for array_unique, array_search, ...
0
votes
1answer
65 views

PHP game - changing color of cells in a blue and white grid => updating groups of white cells that touch each other

My game is a grid in which you have to change cells color by clicking on them. When I generate a grid I have to know all the possible combinations of blue and white cells my game allows, to know the ...
1
vote
1answer
24 views

Custom Block with ACF in WordPress

I'm learning and want to improve as much as possible. In doing so I have written this custom block that has an image on one side and an inner block on the other. It's using ACF to get the variables ...
2
votes
2answers
52 views

Calling multiple ACF field - how do I write my code prettier?

Im using a bunch of ACF fields for my WooCommerce email templates and for this example Im calling these in my email_header template. Im using this with WPML, and need to call each language settings. ...
1
vote
2answers
71 views

Requiring query field to not be empty on search api

we have a RESTful API that includes an endpoint for search apiserver/v5/search?q=[search text] for any query, it passes it off to solr and returns the result like ...
3
votes
2answers
272 views

PHP blogging application with AJAX loading

I have been working on an online newspaper/blogging application with CodeIgniter 3.1.8 and Twitter Bootstrap 4. The latest feature added is lazy loading of posts. From the Static_model (...
1
vote
1answer
36 views

Instantiating classes in WordPress plugin

the last couple of weeks i have been working on my own WordPress plugin. I am trying to do a class based codebase. My plugin works correctly, but i don't really know if this is the correct way to ...
4
votes
1answer
83 views

PHP object oriented programming

I'm trying to learn OOP with PHP (I know it's hard because It's not an OOP language). I'm rewriting my procedural code to OOP.Please provide any feedback on my code, naming and file/folder structure. ...
0
votes
1answer
49 views

Eloquent eager loading deep nested relation with "where" condition

is there a more elegant way to do what the code below does without use "foreach"? I am trying to load answers from questions but only the answers that contains a direct relation with an ...
1
vote
1answer
57 views

Laravel CRUD Controller - code request

Here is my starting point for a laravel CRUD controller. I would appreciate it if someone could do a review and show me how an experienced developer would approach this. I do not want to progress with ...
3
votes
3answers
93 views

PHP fetch an automated email, parse text for specific data, store, send summary

I'm new here. I recently found myself in charge of a large PHP-based system. The guy that wrote it produced some of the worst code I've ever seen. I've never been in charge and have had the luxury of ...
1
vote
1answer
70 views

Prevent Column Name Collision

I have been working on a series of posts about a library to connect to databases but most of the scenarios I have to resort to some "JOIN" the problem arose when two or more tables had some ...
1
vote
1answer
43 views

Method in Laravel to give a JSON response indicating whether the user may edit

I'm working on creating code with a nice balance between concise and readable. How would you improve this Laravel code block to make it more compact and readable? ...
1
vote
0answers
48 views

Displaying Submitted Links Securely On Your Pages

I wanted to allow my website visitors (any Tom, Dick & Harry) submit their links to my webpage for output on my page. I thought it's best to parse user submitted urls before echoing their ...
2
votes
3answers
72 views

URL & HTML encodings on pagination

I wrote this Pagination Section. It shows links to pages 123456789 and so on on SERP (Keyword Search Result Pages). Like you see on Google SERPs. Even though they work, I'm not sure I finished them to ...
-1
votes
1answer
32 views

PHP processed, HTML-CSS, CMS-agnostic, contact now panel

I develop a CMS-agnostic PHP formatted HTML-CSS "contact now" panel, sticky in the bottom of a website screen. The code is tested and works as can be seen from the following image. I ask a ...
3
votes
3answers
84 views

Find common timeslots for consecutive days

Imagine you want to reserve a classroom over several days. You get a schedule, from the school, telling you when a certain classroom is still free. To make it easy for your students, you want to ...
2
votes
2answers
73 views

Sort array of dates

I have this array with dates. All the dates are checked before creating the array with preg_match and check_dates. GoodDates ( ...
1
vote
2answers
168 views

'Lean controller'/'Business logic on service' and filtering, sorting, pagination methods on controllers

I'm currently reading about "Lean controllers"/"Business logic on services" and trying to refactor some legacy code. However I am struggling to apply what is taught in the ...
1
vote
1answer
53 views

Placing store and update logic in Laravel 8 form request

I want some opinions about my code that implements store and update for a Laravel 8 form request. The make function is for storing the data and the ...
4
votes
2answers
36 views

Scrape E-Mails using IMAP from cron

I have the following code which works great to do what it is meant to do. It scrapes the bodies of all e-mails in the inbox at an e-mail address using IMAP and retrieves the unique code sent inside ...
1
vote
1answer
24 views

Output results of a search for usage of a pardot-form

I'm always down to learn better ways of doing thing and I wanted to see if I can get an input from the community to see if there is a way that I can improve this function: ...
0
votes
0answers
20 views

Building a pre-loader for performance gains in Wordpress

As the title, I am building a pre-loader for Wordpress that will deliver performance boosts in loading, as well as metrics such as Google Page Speed. Now, this is something that we do at work, and I ...
1
vote
1answer
64 views

PHP Group associative Array duplicates and make subarrays of different values

I have this type of table: ...
7
votes
2answers
96 views

Connect to MYSQL database in PHP with prepared statements

I have recently learned about using PDO. I created a db class which could handle common actions like create, update, delete and select. Is this method a correct way to connect to the database using ...
2
votes
1answer
37 views

Adjusting variables on change of status attribute of my Order Laravel model on the updated event in observer

I have an order model and a client model. A client has many orders, an order belongs to a single client. In the client model I keep track of how much money a client paid (...
-2
votes
1answer
41 views

Grab user info from database via exec

I'm using the following code to grab user info from my MySQL database via PHP by using exec to invoke a Python script. ...
1
vote
1answer
78 views

Login using two-factor authentication

I want to make the code below prettier but I don't know what to change and how to change. I know that the controller should be easy, delegating actions related to models or to services or something ...
0
votes
0answers
29 views

Create ZipArchive from a directory of files

I am trying to pack around 50 files from a folder to zip file using PHP ZipArchive. Actually, only at most five files are ever changing. Others remain same static files. Should I zip the folder for ...
-1
votes
1answer
55 views

Image upload filter for PHP

I am trying to improve my file upload handler filter. Environment Since any client-side validation is easily circumvented, there is none in this code, for ease of testing. Not even an ...
1
vote
1answer
73 views

backup file script in PHP

I'm learning PHP and try to write some scripts as I go along. I wrote this script and it worked. I would like to know if this script can be improved. The purpose of the script below is to prompt the ...
1
vote
2answers
80 views

PHP File Upload Script

I've put together an example single file upload script that attempts to cover all the things PHP could check for prior to allowing a successful file upload. Is there anything else maybe now available ...
-1
votes
2answers
75 views

Simple Vehicle speed representation [closed]

This code models two vehicle types, with a method to accept a string representing a boost to change speed. How can I optimize performance in inheritance child class? How can I reduce the code inside ...
1
vote
0answers
63 views

PHP SCRIPT OPTIMIZATION OF METHODS

Here is some php code which i think is optimized but still want to optimize it more but not sure how to do it. ...
2
votes
0answers
32 views

Copy images using curl to make API calls

I am a junior web developer currently doing my first internship and I had a lot of freedom to solve small problems the way I thought was best. (There aren't really any developers here so I am ...
1
vote
2answers
87 views

Check URL for keywords [closed]

I'm looking at improving my PHP knowledge and wondering if anybody has any tips on improving and optimising my function below? ...
0
votes
1answer
47 views

Simple web page to enhance browsing of IMSLP music collections

I'm building a simple webpage that allow users to find the intersection of different category lists on a wiki (imslp.org) since the site itself does not offer this functionality. I have a simple HTML ...
3
votes
2answers
125 views

OOP - Contact Form PHP Backend - Procedural to OOP - Dynamic MySQL Prepared Statement PHP

I just converted procedural code to OOP code. Is there any performance or security issue with this code or what should I consider further? interface ...
2
votes
1answer
48 views

Pagination helper class

The most nauseous problem with pagination is the fact that you have to write two almost identical queries. For the various reasons I am not inclined to use the SQL-only way (such as ...

1
2 3 4 5
86