Questions tagged [php]
PHP is a widely-used, general-purpose scripting language that is especially suited for web development.
4,218
questions
0
votes
1answer
93 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:
...
7
votes
3answers
801 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
97 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
934 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
67 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 ...
4
votes
2answers
169 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
82 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 ...
2
votes
2answers
127 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
22 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
50 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 ...
5
votes
1answer
96 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
374 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
63 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
41 views
Add pivot data from the same pivot model [closed]
My project has thee models Cart, Order and Product
Cart ...
0
votes
1answer
74 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 ...
3
votes
3answers
152 views
3
votes
1answer
286 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 ...
4
votes
2answers
81 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
64 views
6
votes
1answer
101 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
36 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 ...
4
votes
1answer
72 views
Social network login and registration forms
I am building a social network with PHP, HTML and CSS and a bit of JS. I want to know how secure my login and register code is.
Register html:
...
1
vote
1answer
157 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 ...
-4
votes
2answers
77 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. ..
...
3
votes
2answers
180 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 ...
3
votes
1answer
87 views
Securely upload multiple image files with PHP
I am working on script to a upload image files Securely. can anyone please review my code and suggest improvements on security.
...
7
votes
2answers
177 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.
...
0
votes
2answers
3k views
PHP/MySQL to delete data from 4 different tables at once
I have four mysql tables setup like the following:
...
2
votes
1answer
59 views
Secure way of uploading php images and GIF
I am creating a social network and I want to know if this is a secure way of uploading pics/gifs and videos.
...
3
votes
1answer
79 views
Model tournaments between teams
In one of my projects I wrote a little tournament platform, but the way I handle participants is a bit messy and I want to clean this up.
So in my case a Tournament can have participants, but either ...
3
votes
1answer
429 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.
...
3
votes
1answer
406 views
Enhancing PHP realpath($path);
PHP realpath($path); is insufficient for some cases since it returns false on paths that dont exist on a file system.
I need a function that extends realpath($path); to return even path that does not ...
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
2answers
97 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 ...
1
vote
1answer
47 views
Importing data from spreadsheet
Not really an issue I am stuck on (the code works) but I just really don't like some code I wrote, if you're bored in lockdown maybe you might like to help.
Context:
I am import some data from a ...
5
votes
1answer
26k views
PHP Register Form - OOP
I'm trying to build my first object oriented system. I'm not sure that my register function below is the best way of approaching this within OOP.
...
2
votes
0answers
50 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 ...
2
votes
0answers
50 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 ...
3
votes
1answer
105 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 ...
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
vote
2answers
104 views
Displaying filtered user data using Ajax and PHP
I want to get my code cleaner and more efficient. This code gets variables form a PHP file and filters it to show the selected user name, all available usergroups on a list box and the groups he is ...
0
votes
2answers
66 views
Set id in constructor, or generate it when asked for?
I'm using PHP, I have a class that generates an id based on the calling class, so the id of the class won't change after it has been initialised, now I'm wondering which of my two methods is ...
2
votes
2answers
113 views
Structuring code logic for events on laravel controller
The code below will store a base64 image on another website and create an event to display the image on a Vue page in real time. It works fine and all.
My question is, is this a good way of doing it ...
0
votes
0answers
11 views
Structuring code logic for events on laravel controller [duplicate]
The code below will store a base64 image on another website and create an event to display the image on a vue page in real time. It works fine and all. My question is, is this a good way of doing it ...
3
votes
2answers
104 views
“Guess a random letter” game with command line interface
The code below if launched on the command line is a simple guessing game.
A random character 'a', 'b' or 'c' is chosen, and the user is prompted until they guess correctly.
It's arguable that invalid ...
4
votes
1answer
60 views
Checking for duplicate email in api response data
I am working on a small internal app that works along an external API for provisioning purpose.
The code essentially is comprised of a series of forms where the user inputs data, this data is then ...