Questions tagged [php]
PHP is a widely-used, general-purpose scripting language that is especially suited for web development.
4,178
questions
1
vote
0answers
45 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
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
111 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
94 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
78 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
36 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
62 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
41 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
71 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
67 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
622 views
Server side form validation library
Have I followed best practices for PHP development, or can this class be improved?
GitHub
...
2
votes
1answer
339 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 ...
30
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
126 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
27 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
28 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
35 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
63 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
72 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
788 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
89 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
866 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
211 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
168 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
92 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
77 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
118 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
21 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
45 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
169 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
351 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 ...
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
36 views
Add pivot data from the same pivot model [closed]
My project has thee models Cart, Order and Product
Cart ...
0
votes
1answer
73 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
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 ...
2
votes
1answer
196 views
Prefixing prices of certain product categories with text in Woocommerce
I had the need to prefix the price for certain product categories on only the shop page (because the price can be higher depending on extras that the customer might want).
These were my requirements ...
3
votes
3answers
143 views
3
votes
1answer
234 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
54 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
80 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, ...
2
votes
1answer
44 views
6
votes
1answer
92 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
1answer
2k views
Formatting a date range, with shortening if the interval falls entirely within a calendar month
The graphic guy wants to display dates like
16. February
17. - 24. February, or
...
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 ...