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
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 ...
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 ...
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 ...
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: ...
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
70 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
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 ...
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 ...
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) ...
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 ...
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 ...
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 ...
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: ...
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 ...
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 ...
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 ...
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
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 ...
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
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-...
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 ...
5
votes
2answers
142 views

Queries to get unpaid and unpaid invoices

Here is my code: ...
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 ...
3
votes
1answer
197 views

Sanitizing user form input in php

Security threats in mind: SQL Injections!!! --- Solutions: Prepared Statements (PDO) and including $bpdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); in ...
3
votes
0answers
53 views

Mysql PDO Wrapper that throws Unique Constraint Exception

The main reasoning behind this PDO wrapper, is that I find myself using unique constraints quite frequently in my designs, and I have ...
4
votes
2answers
74 views

PHP Email List Sign Up

See my original post: here. I have one html page and four php files that allow users to sign up for an email list. One of the php scripts is a cronjob that deletes unverified rows older than 24 hours, ...
3
votes
3answers
136 views

Email Validation in PHP

Is this script sufficient enough to validate user email input? ...
2
votes
1answer
37 views

Route Improvement in Laravel 8

I have below route. I am using Laravel 8. ...
2
votes
1answer
34 views

Modify parameter data before creating an instance of a class in PHP

I have an abstract Badge class, every class extending this class should always correctly set the incoming name (string) and achievedAt (date) fields. There might be other classes that extend the Badge ...
6
votes
1answer
85 views

binary data shell echo generator

edit: here is a cleaned-up version incorporating most (but not all) feedback, thanks guys; https://gist.github.com/divinity76/79efd7b8c0d7849b956cd194659c98e5 I need to... generate a linux shell ...
-4
votes
2answers
69 views

Is this a good approach to replace mysqli_num_rows? [closed]

Is this a good approach to replace mysqli_num_rows? $db is a PDO instance. .. ...
2
votes
1answer
38 views

Get all routes that start with rt_

The code reads all my routes and return to my JQUERY AJAX the names of the routes without duplicates and just those that have "rt_" prefix. ...
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 ...
3
votes
1answer
421 views

Very simple encryption API

I need an encryption system with a super simple API. I'd prefer something as simple as the following. The output should also be browser-friendly and ideally url-friendly. ...
1
vote
1answer
55 views

Improvements on Laravel's base Model and FormRequest

Introduction I've improved, IMO, Laravel's base Model and FormRequest. It's working as expected. But, before actually implementing this any further in my application, i want to have my classes checked ...
3
votes
2answers
179 views

Contact form with spam-prevention - follow-up

Background The basics of this project are already covered here. I received the suggestions to: not create the exercise with JavaScript. use pictures instead of plaintext. I tried to implement the ...
1
vote
1answer
47 views

Class dedicated to transforming API response to the data I need?

I have the following code (in php) that calls the open weather api with my credentials, and returns data for me. Know I'm returning some data I pick from that response, I'm wondering if it's good ...
1
vote
0answers
32 views

PHP Laravel Order generation Custom Class Refactor

Here is a custom class code I use to handle different types of orders in Laravel. This question includes the code regarding Order Type A. I want to know whether I can simplify the code more. I have ...
7
votes
2answers
127 views

PHP Mandelbrot Set Generator

I need to get familiar with web programming, so I decided to write up a fairly simple PHP page that accepts GET requests and serves back an image of the Mandelbrot set... as a table of colored cells. ...
2
votes
0answers
46 views

API Client and usage implementation

I'm really bothered with my approach in this, as I'd like to use the client in multiple projects. The client is just extending Guzzle and I'm using a factory method to initialize the client with the ...
2
votes
0answers
46 views

A UserService method that calls the UserRepository a few times

I'm trying to implement some domain driven design architecture, such as a repository to talk to the database, and a service that talks to the repository. I have an action where I want to see if a User ...
3
votes
1answer
101 views

Contact form with spam-prevention

Idea After a handfull of small javascript-projects, I also wanted to work a bit with php now. I decided to create a simple contact-form. Of course, I wanted it to be as spam-save as possible, so I ...
1
vote
2answers
68 views

Dynamic Accordion in WordPress

I used the Bootstrap v4.0.0 accordion to display my business services. Further, I created a custom post type "service" for my services (Each service is a post). To display my services ...
4
votes
1answer
24 views

Creating formatted “[time] [unit] ago” messages from a seconds value

I have this function which calculates how many seconds, mins, hours etc ago a specific time string was. However, the way I have done it consists of a massive if statement block, and it goes through ...

1
2 3 4 5
84