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
5
votes
1answer
93 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. ...
18
votes
4answers
3k views

PHP gaming community website

I created a gaming community website about 13 years ago. It uses PHP, SQL, HTML, and CSS, and does not use a framework or template engine. It includes features such as a login system for members, ...
2
votes
1answer
49 views

I want to most efficiently use array values and variables in a WordPress template while abiding by PHP/WordPress best practices and standards

Is it better to validate and put an array value into a variable at the top of a file or to check the array value directly right before output in the file? I work at a WordPress shop and we have a ...
6
votes
2answers
417 views

Checking if an array of dates are within a date range

I created a dates_in_range() function which checks if all of the dates passed to it ($dates array) are within ...
2
votes
1answer
63 views

Extract string between first occurring set of parenthesis

I have this function and need to refactor it Please refactor the code below to make it more concise, efficient and readable with good logic flow ...
6
votes
0answers
54 views

Wrapper for Google_Service_Calendar as a Symfony service

My app interacts with Google Calendar. This Service wraps Google_Service_Calendar: ...
1
vote
5answers
1k views

Readability of array_* vs foreach in PHP for filtering and extracting

With functional programming all the rage, I feel I should be using PHP's array_* functions more. But when I compare these two identical implementations, I can't ...
4
votes
2answers
219 views

OO and non-OO usage of Mysqli

I'm starting to learn the object oriented aspect of PHP. In this regard I made a small "exercise" of sorts "translating" one of my PHP functions into OO mode of PHP. I'm asking if there are there any ...
4
votes
3answers
211 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 ...
2
votes
2answers
79 views

Dynamically displaying or hiding checkboxes based on region selection country. Also select All / None included

This is basically my first real venture into JS coding ... I think what I have put together here is quite long-winded and could be streamlined but I'm not quite sure how. I have a table with Columns &...
1
vote
1answer
35 views

Merge nested arrays coming from a database and a form

I need to update a nested array of settings. There are several difficulties that I managed to solve, but I'm pretty sure the code can be written much simpler. I just don't know how, which is why I'm ...
9
votes
1answer
163 views

Chart of Percentage questions Answered

Every day, Duga reports the number of unanswered questions and percentage of answered questions (after she calls the API endpoint /info) in The 2nd Monitor (so we ...
3
votes
2answers
146 views

Sanitize vars on form submit

I have this code and I would like to know if I filtered my code correctly. I am practicing my security coding for a system that I am working on and I would like to know if I am doing it the right way. ...
3
votes
1answer
64 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 ...
4
votes
1answer
72 views

Custom WordPress Menu for posts

I have recently delved into the world of OOP programming with PHP. I wanted to add my own custom menu to the WordPress Admin area, and came across a tutorial, which I have followed, and the code is ...
0
votes
1answer
121 views
3
votes
2answers
53 views

PHP Image Upload and Validation

I have a PHP script that uploads an image file, checks it for size, extension, and type. It then converts it to png, saves it to a folder outside the web root with a randomly generated name, then ...
15
votes
2answers
14k views

Simple Tic-Tac-Toe PHP/Pure HTML

I've been doing a simple Tic-Tac-Toe with PHP, generating only HTML code. A few notes: I didn't bother yet to give an AI to the opponents (the Os), and it is intentional. There is no CSS style to ...
2
votes
1answer
69 views

PHP JWT management base library for inclusion in larger projects

Edit: this is a base library for including in larger projects for the overall management of JSON Web Tokens (JWT) that should be compatible with other JWT libraries that share an encryption secret - ...
0
votes
1answer
118 views

Recieving an XSS Injection: <script>alert('xssvuln');</script>

I would very much appreciate it if someone could review the php script below for any security risks. I have a live website using shared hosting. There's a page that accepts text submissions from users....
3
votes
2answers
97 views

Process POSTed data and add default string if missing

My code takes the input submitted by $ _POST, via a checkbox array. I process the array and check the sent data if there is a particular string in it, which is set ...
2
votes
1answer
99 views

Shoutbox system

I wrote a little Shoutbox System which is working fine, but I want to know if there is something I can improve about this code. Here is my Shoutbox Overlay: ...
4
votes
2answers
694 views

Classes and variables in PHP

First of all, I'm trying to learn OOP PHP, so any advise will be great. My idea is to create some kind of MVC Framework CMS kind of thing, just to learn OOP PHP and MVC well. Let's say that I've got ...
2
votes
1answer
125 views

Implementing Decorator Pattern

Context I'm looking into design patterns. My first try is using the Decorator Pattern. Question: Is there another (maybe standard) approach to applying modifications in a decorator other than ...
2
votes
1answer
2k views

Separate areacode from phone number string with MySQL Database

I have a database with 5000 entries of local area codes to separate the area code from a phone number string. I'm not sure if the code I use is the fastest way to solve these job. I shrink the ...
2
votes
1answer
69 views

A lightweight CRUD, based on the Table Data Gateway pattern

In order to reduce the boilerplate code, I decided to write a lightweight database helper, based on the Table Data Gateway pattern (or at least the way I understand it) with the aim of using it for a ...
0
votes
1answer
58 views

Faster way to intersect arrays

I need to intersect lots of arrays with each other. Those arrays are like: ...
2
votes
0answers
76 views

Creating calendar - Speeding up PHP script

I'm working on a calendar for my office. Every people has his own column and there is a line for every day. There are some periodic date, where, for example, given people have to be working on the ...
2
votes
1answer
53 views

PHP Laravel Order generation Custom Class

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 ...
2
votes
1answer
63 views

What good practice to use for input data with arrays?

I'm a beginner and I wonder if Is what I have created a good practice as a structure and way of working for input data processing? Is the way I wrote the index.php file a correct and secure way of ...
27
votes
4answers
2k views

PHP Autoloader Library

Basically, I had written this class a little while ago to ease autoloading of our local libraries. The premise is that everything is split by packages into multiple layers of sub-packages. Classes ...
1
vote
0answers
38 views

Getting output of a NodeJS script in PHP [closed]

I'm using a NodeJS script to do some geo calculations using the h3.js library by Uber. the concept of getting a nodejs script result back into php is new to me. I found the following example online, ...
4
votes
2answers
327 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
26 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
58 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
5k 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
27 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
156 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
132 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 ...
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
44 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: ...
1
vote
0answers
78 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
623 views

Server side form validation library

Have I followed best practices for PHP development, or can this class be improved? GitHub ...
2
votes
1answer
343 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
261 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
28 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
31 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
38 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 ...

1 2
3
4 5
85