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
1
vote
1answer
94 views

What is the common API endpoint architecture using DTO?

Hey I always used to create some pretty messy endpoints and I decided that it's about time to start writing cleaner code, I'll provide an example of how would I design an endpoint and I'll be ...
6
votes
1answer
74 views

Generic memoize utility function for pure functions

Given the following generic memoize utility for pure functions with type hints: ...
3
votes
2answers
173 views

Simple single-file PHP login system

This is something that I initially came up with to protect a bunch of scripts on my personal webserver, but am now planning on using with a few public projects too. ...
2
votes
1answer
114 views

Request mixed with JSON strings and array fields, in custom function for reduction need Simplify/Refactory

Client From a POST request I get a mixed structure of an array and JSON. To handle multiple type of elements I am using var_dump to get the passes. For ...
2
votes
3answers
2k views

Validator Class in PHP

I am trying to create a validation class that can be used to validate many forms of my webpage in general. It makes use of the database as well to verify records. The problem with it is that it ...
8
votes
3answers
1k views

How secure is my PHP registration script?

I coded a registration form and was wondering if anyone could give me feedback on whether I'm lacking any major security mechanisms. I've done loads of reading around the topic and feel it should be ...
7
votes
4answers
224 views

Cleaner or better readability in URL composition

I have a URL that is hardcoded via a config which I extract into a config: ...
4
votes
4answers
62 views

Create unique string from id to build an link shortening system

I want to build my own link shortening system. Therefore I need a way to create unique strings from the record ids stored in my database table. So far I came up with this. I wonder if you now a faster ...
5
votes
4answers
661 views

Optimized solution for a rolling dice code puzzle

I was asked to provide the solution of this rolling dice problem in an interview. When I showed him my solution, he said that there is another way to find the solution. I am looking for answer in PHP ...
2
votes
1answer
62 views

Login system in PHP using AJAX

I am beginning the cycle of creating my role based access control into my framework. I now want to log the user into my application and my _user table looks like this: ...
2
votes
3answers
61 views

Receiving a user's registration submission and inserting row into database #2

I asked this question before and mickmackusa and Your Common Sense gave me some good answers. I went over them and made as much ...
4
votes
1answer
92 views

Rock, Paper, Scissor - Game

This is my first ever created game. I been slowly but continuously learning PHP for the past 2 months and just last night I thought that I might be able to create a simple and very basic game. Due to ...
4
votes
1answer
61 views

Improving efficiency of download code

I'm in the process of reviewing some old code released by an old colleague. We have a cronjob that executes once in an hour to download some thumbnails: the paths to the thumbnails are stored in a ...
3
votes
1answer
53 views

WP/PHP getting API data and using hook

Below are the two things I'm trying to solve, logically. This is just a proof of concept; and I'm not implementing this on real data nor via full plugin at this time. Just looking at logic and syntax ...
-1
votes
1answer
61 views

PHP template MVC [closed]

For several days I have been learning about MVC, and I do some code but I don't know if that is correct. I will be grateful for some tips to get this code better. Here is my github respository https://...
1
vote
0answers
34 views

Booking system ala airbnb many to many laravel relationship? [closed]

I'm trying to create a system to log all bookings for a few airbnb hosts, at first I had two models Home and Guest, where a home can have many guests and a guest could book for many homes, then I ...
1
vote
2answers
97 views

Receiving a user's registration submission and inserting row into database

I have improved my code since the last time asking for its review. I'd like to know if it is up to the current standards. ...
1
vote
2answers
113 views

Return row count from mysqli prepared statement

I want to know if it is okay/safe to use a prepared statement and mysqli_num_rows like this: ...
2
votes
3answers
628 views

PHP + MySQL beginner, any tips appreciated on the approach

Any tips or review points are appreciated, I'm not much familiar with server-side web-dev (PHP) and DB. Few things of note: I see no reason to separate codebase into different files and bother with <...
2
votes
1answer
68 views

Securely connecting to my DB [closed]

Hello all I have a short question. Is this a good and secure way to connect to my DB ? ...
1
vote
2answers
118 views

How clean is my close_account code?

Hello i'm coding a social site and I need to know how clean this code is. I read other answers people told me from my previous questions like this and used it as guidelines. So now I wanna know if ...
2
votes
1answer
64 views

Controller in Laravel with parsing, creation and relationships

The following code represents the store method of a resource controller. A user can create an training offer on my website and can pass various information like ...
3
votes
2answers
63 views

Getting data from database through Ajax post request

Is the method used below to get data from a database efficient and optimal? The data is in a MySQL database, and in my server I have a PHP file with the following code to return some information: <...
1
vote
1answer
51 views

Google People PHP best practise to get OOP

I need to log in users to web app in Javascript and PHP. So I have Javascript interface which send me accessToken to PHP which stores users data to DB and log user in. But the result code does not ...
3
votes
1answer
108 views

How secure is my login and signup code

I am creating a social network and I've been told a few times a lot of things are outdated and prone to SQL injections so I am going over everything with a very fine comb and checking what's good and ...
3
votes
2answers
350 views

messages.php file security and efficiency

I am creating a social network and I want to know how secure and clean this code is. I had to update it to prepared statements because I was following a tutorial and even though it was made in 2019 it ...
4
votes
2answers
369 views

Very simple login script review

I'm relatively new to PHP and have recently created a small website for friends and family to upload and share photos, protected by a very simple login system. While I'm aware what I'm doing isn't ...
6
votes
4answers
1k views

Regex to validate font names

/((([\w -]+)|("[\w -]+"))( *, *)?)+/ http://refiddle.com/18ql I'm trying to use a PHP regex to sanitize a user input for a list of fonts. The above one seems to ...
1
vote
2answers
96 views

Shorten and optimize php custom code for wordpress page template and use shortcodes

I'm pretty new to php coding, but i know wordpress for a long time. Also experimenting with bootstrap. I created a new Page Template and modified it a bit. What I'm looking for is to optimize this php ...
3
votes
1answer
37 views

Performance of WordPress Plugin is currently very bad and needs to be improved

I have written the following Plugin, which adds fields to the Media/Attachment Entries and returns all information in one Shortcode. This solution works, however, is pretty slow the more entries ...
2
votes
2answers
78 views

Unnecessary loop in database population

I was looking over some code that I wrote years ago (that is still technically working, albeit on a very quiet production server) and I came across this segment of code. ...
2
votes
2answers
52 views

Is this code is safe or not (img upload) ? [PHP]

I'd like to know if this code is usable, because I'm not sure, thank you. The code is used to upload images to a predefined folder for users. ...
0
votes
1answer
57 views

Recursively displaying json data on website [closed]

I am displaying the data from a json file onto a website, with recursive and iterative tables side by side. i have the iterative code working, but I have no idea on how to make it recursive. Here is ...
3
votes
1answer
79 views

Parse and format var_dump data to become more readable

I have a class that exposes var_dump data in order to get better human readable layout. I have achieved this with a lot of ...
36
votes
7answers
95k views

Setting a default value if a variable is empty

This is the pattern I've been using for "if the variable is empty, set a default value", and for variables like $muffin, it has all seemed well and good. But in ...
1
vote
2answers
154 views

Is this code written safe from attacks?

I have small question. I don't know much about JavaScript (jQuery) or AJAX and I don't know whether I'm doing it safe from XSS Attacks, SQL injection and that stuff. I think the PHP with MySQL would ...
7
votes
2answers
5k views

Generate 6 random numbers for lottery in PHP

This program generates 6 random numbers between 0 and 45 and the numbers cannot be repeated. Can this code be improved? ...
2
votes
1answer
58 views

What is the best way to use serverside validation in PHP PDO?

I have a form on my page. I am using jQuery validation for client-side and PHP for server-side validation. I am using PDO. I don't have any issues with client-side and server-side validation. My form ...
2
votes
1answer
65 views

Using method trait to return something in laravel model

I have question about scope yesterday, and someone gives an answer to don't return anything in scope. Is return something in scope really bad practice? Should I not return anything in the model ...
7
votes
1answer
210 views

Using TinyMCE with responsive file manager PHP and Javascript

I use TinyMCE with responsivefilemanager and I wanted to know that is my code well-written maintainable and readable, Sorry If this sounds like a stupid and basic question because this is such a basic ...
3
votes
2answers
59 views

PHP Status class : pattern or anti-pattern

I want to abstract some code which does a bunch of checks and returns a boolean - since I am using the business logic in several places. But I also want to get back the reason why, if it was returned ...
1
vote
0answers
37 views

Secure/Bulletproof Image Upload Using PHP

Here is my code that check and upload an image to my website. Is this code really secure against uploading of malicious codes ? Anything i have to add to this code to make it more secure?, I have ...
1
vote
1answer
52 views

Handling multiple try-catches in a for loop

Good day! I would like to know if this is possible to be refactored into a cleaner code. The reason I'm doing it like this is to catch the column that the error appeared on and then potentially output ...
5
votes
2answers
248 views

SOLID principles breaking in interview task (file parser)

Originally asked on Stack Overflow I recently had an interview where interviewers asked me to Rewrite following code with SOLID principles. Add a new file handler (...
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 ...
7
votes
2answers
590 views

PHP MySQLi Connection File

I have recently adjusted the way I create my mysqli connections. Initially I would include the connection file and use ...
2
votes
1answer
95 views

Does this PDO process look protected from SQL injection?

Does this process look protected from SQL injection attacks? Is there something I could possibly change to make it more protected? ...
3
votes
2answers
95 views

Checking if naughts or crosses win in Tic Tac Toe

I am working on a coding challenge for Tic Tac Toe. I am calculating the results and inserting them into the database. However I have a long and messy if statement, which checks if the array's values ...
5
votes
1answer
217 views

SQL QueryBuilder

I've made a simple querybuilder for my job, but I'm kind of insecure about starting to use it because I'm afraid of errors happening when I start using it. I've done some tests with ...
2
votes
1answer
1k views

Composing an HTML email body in PHP swiftmailer

The following code is what I'm using to send a password reset email. The specific part I'm referring to is how I'm setting $message. Would there be a cleaner way to ...

1 2
3
4 5
84