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
3
votes
2answers
49 views

Adding, removing, and changing user names and passwords in .htpasswd with PHP

Some code I wrote to add, remove, and change user names and passwords in .htpasswd with PHP: ...
4
votes
2answers
72 views

API for SQL queries with PHP PDO

I'm writing a very simple CRUD application, and I'm wondering if the way I'm using static methods throughout the code makes sense. I'd very much like to simplify ...
4
votes
0answers
45 views

Basic login system with 2 factor authentication

What I try to achieve I need to create a administration-panel for a website. Therefore, I need a possibility to protect the content of the panel via a password. The functionality doesn't have to be ...
2
votes
1answer
71 views

Wordpress Ajax Custom Query - High CPU LOAD

I'm developing a fully AJAX community WP theme that comes with a lot of custom queries. Everything is fine, there is no bug but recently but I had a few clients that have a huge database and my theme ...
0
votes
0answers
9 views

How to restrict a user to use only one plugin in WordPress

I want to restrict a specific user to use only one plugin. I don't want him to see any other pages on the WordPress admin dashboard like the Plugins page, Posts, or other pages. I want to show him ...
6
votes
1answer
1k views

Multi-query PHP Parser for SQL files

I have an external project, which needs to run an SQL file containing multiple SQL queries (a bit like mysqldump, if you like, but is user-created, with any kind of SQL statement/definition). PHP ...
1
vote
0answers
30 views

Is it okay to use interfaces on tests?

I have created a test, also the interfaces to be implemented for each test case based on user's role because I think it would make it easier to understand what the test case will and should do, also ...
5
votes
3answers
4k views

Codeigniter Model Optimization

I have created this model for Codeigniter. It's working fine, but I need to know if it can be more optimized. ...
0
votes
2answers
19 views

Template file for creating formatted webpages

This is my working template file which I manually edit to create new properly formatted webpages for my personal website. I am interested in what advantages if any could be realized by placing the CSS ...
5
votes
1answer
69 views

function for PDO queries and return result - tested - any tips?

I write a function using PHP and MySQL, to get PDO connection, query and array of placeholders to execute query and return result. I test this function and it has good response when result for ...
1
vote
2answers
70 views

Implementing Pagination with Twig in Codeigniter 3

I am working on a online newspaper/blogging application with CodeIgniter 3.1.8 and Bootstrap 4. I have decided to add themes to it. The application is not HMVC, only MVC. I thought it was a good idea ...
1
vote
1answer
76 views

Repeated DB connection at max user connections

I am trying to create class with connect to mysql database. And if there is max number of connections I want to wait and try it again. I figured out, how it can works, but I am not sure, if its the ...
5
votes
1answer
2k views

Optimizing cron job for sending reminders

The following script is being run with a cron. It runs once a minute to see if there is a reminder that needs to be sent. Should I make this run once every 30 minutes? The choices to send a reminder ...
1
vote
0answers
29 views

Handling user sessions on website using $_COOKIE and $_SESSION

So I am building a website. It will be only used inside our small company and it's not made for public use. What I want to achieve is the ability for user to maintain session after sign in for a ...
3
votes
1answer
60 views

Custom exception for each invalid input value

I have backend project in which there's own "parent-to-all exception" exists, something like this (also I have InvalidArgumentException derived from this exception): ...
1
vote
0answers
34 views

Good practice for dB connections

Is it good practice to keep the connection strings for websites in another folder outside of the site folder? For example, here is the htdocs structure. I am working on site3: ...
2
votes
0answers
49 views

Make Pagination using Ajax with Jquery, PHP, History.pushState()

Finally after a few months of searching and learning ajax with pagination php and History.pushState() I created ajax php pagination. Test page 1. Ajax(index.php) ...
2
votes
0answers
66 views

Make Pagination using Ajax with Jquery, PHP [closed]

This is the first time that I have add (I mean, I try) Ajax with Jquery to PHP and Mysql (pagination). This is a link to the test page: testpage1 I think everything works, but is it done correctly? ...
1
vote
1answer
621 views

Server side form validation library

Have I followed best practices for PHP development, or can this class be improved? GitHub ...
2
votes
1answer
338 views

Custom error handler for PHP

I've written a custom Error handler for use in PHP. What it does is simply capture PHP errors, and logs them using Monolog. It works, but I can't help that it has too much stuff inside. I could ...
29
votes
3answers
37k views

CodeIgniter Active Record Subqueries

I use CodeIgniter at work, and one of our model files had a lot of subqueries in it. I originally had to manually write each subquery, and wondered if I could use active records instead. So, to make ...
5
votes
1answer
77 views

Laravel Scope get request data/param

I want to pass the param from the request on the scope method in the model and serve it as json to be rendered by select2. Which is better? 1. Pass request from the controller like this controller: <...
1
vote
0answers
23 views

How to put my functions outside a class to get organized, Design pattern [closed]

I'm using Symfony 4, I have a class named Fiche, it contains the attributes and by default the getters and setters functions of course. Inside this Class, I have created over than 107 others functions ...
2
votes
1answer
26 views

Is there a way to consolidate Ajax dropdowns that filters data from MYSQLi database

I recently started a project which has a database of rail cars for a train simulator. Im trying to set up a way to filter the data based upon 4 categories "Car Type", "Road Name", &...
3
votes
1answer
33 views

Classes for the blog (PHP)

There is a task to create site-blog on PHP. I have made some classes, but my Senior reviewed them and said that approach is bad and "best practicies" need to be used. What did he mean? Any ...
6
votes
1answer
55 views

Website user registration script in PHP

I have a registration system, but I really don't know if it is safe, because I don't understand security very well and I'm afraid of compromising my clients' data, I believe that the methods I created ...
0
votes
1answer
67 views

PHP array with array value into multiple arrays with same key

Very difficult to explain in a sentence sorry so here is example. I have this array: ...
8
votes
3answers
780 views

Reorganizing unorthodox PHP phone book project

I've been learning PHP and I've created a phone book webpage as an exercise. I am satisfied with the way it works -- it seems to handle all possible input cases correctly, and the interface feels nice ...
2
votes
1answer
85 views

Is execution of sql in my php code safe?

So I have two PHP files that execute SQL code in them. It's a simple registration script and an account recover script. I want to know is my code safe from SQL exploits & other exploits? Here's ...
3
votes
2answers
830 views

Compress svg files in PHP

I wrote something to "compress" svg files. The svg files I am using often have comments and empty <g> tags, and I want to remove them. My main goal is not the ...
6
votes
1answer
66 views

upload multiple images and resize

I've written PHP code to upload multiple images to a server. This function processes a maximum of 10 images at one time and if any image's width or height is larger than 2000px it will resize it. But ...
2
votes
2answers
203 views

Address class in PHP 7.4 with types

About this exercise I found out there is a form of strict types in PHP 7.4, so I freshened up my PHP coding with this simple Address class. I did not use PHP since ...
4
votes
2answers
165 views

Security of post submission, picture upload and post fetch

I am a newbie and have been following a tutorial I bought on Udemy. But I was told it is old and teaches bad code practices. I used this in some code from my old projects. Now I'd like to know how ...
3
votes
1answer
90 views

Performing CRUD between 4 tables

This code works perfectly fine but I have repeated many lines of code in this controller. I need some suggestions on how to optimize this code and remove repetition, with focus on the ...
3
votes
1answer
72 views

OOP: The correct use of classes and optimizing code

I am trying to improved my coding skills. I mainly work in web development. I had a "system" that I use in all my projects to fetch data from my DB to the browser. I tried an implementation ...
8
votes
1answer
9k views

Simple Router class

I made a simple routing class that I like to get reviews for, mostly because I do not know how to make it SOLID, since I even made this class separate from the HTTP response/request for the sake of ...
5
votes
1answer
66 views

Wordpress single post content class customization with if-else function

I have the following code, which displays the content for my custom page template "landingpage.php" and for single posts. The site is based on Bootstrap 4. ...
2
votes
2answers
116 views

Secure file upload for PDF only

I am trying to create a secure file upload using PHP 7+ where I only allow PDF files. I found a lot of posts on this topic on different websites but couldn't find a complete solution that ensures that ...
2
votes
0answers
19 views

Correct way of doing transactional queries [closed]

I am trying to do multiple queries in one call, so I organized my code as below: ...
4
votes
3answers
187 views

PHP comment system

Basics I created a simple comment-system. My goal was it to create a system that can easily be used on everyone's server without having to install a load of programs. I also tried to create it as ...
4
votes
1answer
42 views

Create a CSV from SQL Data and email as attachment using PHP

I put together some functions that allows a PHP script to send the SQL data obtained from user inputs on a website via an email attachment as a CSV file. It works perfectly and I have no issues with ...
1
vote
1answer
161 views

Laravel show and update currency from rest api

I need: Daily save new exchange rates from the REST API in the database. Return the current exchange rate for a given currency, the whole table for a given day, the exchange rate for a given currency ...
5
votes
1answer
89 views

Whitelist for textarea and save input to file

I'm working with product codes, so a user can only scan these type of product codes into a textarea element. I don't know if my code is written the best way possible, or has good performance. I'm ...
8
votes
2answers
327 views

RGB <-> HSL converter + hue shifting

My input is basically a .png image from the img/ directory (I figured out that I should parse it, because there is an exploit ...
2
votes
0answers
31 views

I need a better way to add css per each page on wordpress

I just started to use Wordpress to start building a website, but as I need to use the get_header() function to retrieve the ...
3
votes
1answer
62 views

Filtering multiple request parameters

This is pretty straightforward, it takes requests from the frontend, checking if it is present on the request, if it does, an action is taken for that if statement. I wonder if there is a way to ...
3
votes
0answers
29 views

Add pivot data from the same pivot model

My project has thee models Cart, Order and Product Cart ...
0
votes
1answer
72 views

Learning factory design pattern [closed]

I'm making the very common example of Factory design pattern which creates a factory of cars and return an instance of a car. I found a example here https://refactoring.guru/design-patterns/factory-...
5
votes
2answers
142 views

Queries to get unpaid and unpaid invoices

Here is my code: ...
2
votes
1answer
74 views

Should I separate the classes in types and increase decoupling?

My goal is to make a form builder class, that generates bootstrap 4 form inside a modal. My doubt is whether I should leave it as is or if I should crate a interface and then implement that interface ...

1
2 3 4 5
84