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
2
votes
2answers
54 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
88 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
97k 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
157 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
86 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
75 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
464 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
62 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
47 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
55 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
261 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 (...
7
votes
2answers
606 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
96 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
128 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 ...
0
votes
0answers
52 views

This service submits an application to a 3rd party API and returns a URL to redirect to. It does too many things. How can I refactor it?

A user applies for a lease for a car and on approval, can submit the car they want to buy. The service is consumed like so in the controller one layer above: ...
5
votes
1answer
93 views

getRandom() - Randomize array and get result

I've written a function that allows you to pass an array of values, which is then shuffled and returned based on a parameter $preserveArray. This is the code: <...
-3
votes
3answers
337 views

Registration code [closed]

I was following a tutorial for a social network. I want to know how secure this code is because I plan on launching it to the public web. ...
0
votes
1answer
132 views

REST API PHP find by id

Description: The web server retrieves data from file database (pdf, doc, 3d file, zip and rar) and financial program such as inventory, price, indexes, order status and so on. I'm doing REST API PHP ...
2
votes
1answer
43 views

Using dynamic methods to build SQL queries in CodeIgniter

I'm using this class as Modal in my CodeIgniter project, as I'm newbie in CI, I wanna know if this has some issues, I'm using this modal for all queries, like I call this with parameters and it ...
-2
votes
1answer
55 views

Laravel Page Controller [closed]

Aim: To make pages located in site.com/page-1, site.com/page-2. Those pages are pretty much static so I won't use database. First, I've created the PageController. ...
1
vote
1answer
101 views

How secure is my registration code

Hello I am a beginner in PHP and I need some opinions. How secure is my registration code ? If I launched this on the web would you feel safe signing up with personal info ? ...
2
votes
2answers
19k views

Merging two multidimensional associative arrays

I just wrote a function that will loop through two multidimensional associative arrays and merge them together based on the key names and their values. While I'm satisfied that this function works, I ...
3
votes
1answer
38 views

PHP get minDateTime from array

I've written a function to get the smallest date from an date[ ] and check for null. If null == infinity ...
1
vote
2answers
152 views

PHP - How can I refactor this store function (which handles different database operation for user types) in order to reduce duplication?

I'm simply using Slim PHP MVC framework in my API project. PDO::FETCH_ASSOC is used in the database calls. So no data objects. The router handles requests and pass to the controller. controller calls ...
1
vote
1answer
67 views
3
votes
1answer
61 views

More protection needed? PHP secure

I am busy on a protected page with login and I want know if there is more protection needed. It is a very simple system without database etc... authentication.php ...
3
votes
1answer
112 views

New comments after a user's last comment

Edit: I've added everything I can... I have the following query, which gets the last comment from the user in a given topic, then I check in the while loop if there are newer comments. My problem is, ...
5
votes
3answers
3k views

A demonstrational example of a Data mapper ORM

I want to create an educational example of a Data mapper type ORM. You know, it is always interesting to know how the stuff works, but when you take a fully functional software package, it's just ...
2
votes
1answer
72 views

PHP OOP - Login & DB adding/removing script

I've created something that I called System, where you can login, create the files and delete the files. It's not any kind of big project, but it's the biggest project I made in PHP OOP so far. It ...
2
votes
1answer
64 views

Create user in users table and insert data into second table with one form in Laravel Relationships

I'm trying to create a user while adding data to a second table via one form: users table: ...
1
vote
1answer
86 views

Is this an good OOP Design in MVC PHP for getting User Details?

I was given a API project by my co-worker to work on half created a system in slim PHP. The project consists of the Models and controllers. When the route is called it calls the Controller with the ...
5
votes
1answer
94 views

Defining routes and controllers relationship for given pages

I'm building a CMS app with the help of a custom framework. The back-office is composed of the following pages: post list page list user list post edit page edit user edit Actually, my routes are ...
4
votes
3answers
50 views

PHP/HTML Table and Modal Forms that display information

Its been a while since I have written PHP or HTML for a project, so I could use some thoughts on improving the code below. I wrote all of this going off of old knowledge, so I imagine its really ...
2
votes
2answers
66 views

Continually refresh game data using AJAX

I've been working with JavaScript and AJAX a lot in the past, and now I'm moving towards the backend and working with databases more. I want to update my game data in as close to real time as possible ...
1
vote
1answer
49 views

PacMan in JavaScript and SVG

So, I happen to know a bit about front-end development, and I'll make a seminar at the university about it where I share that knowledge with my fellow students. A few years ago, I've made a PacMan in ...
1
vote
1answer
51 views

Chain of responsibility and handlers dependent on each other

I'm importing data from file to many tables in database. It may look like this: First Name, Last Name, Meeting John, Doe, 2020-04-24 08:00:00 Some fields like "...
2
votes
2answers
119 views

PHP Factory Pattern : Should I use `create()` or `__invoke()`?

I currently had a colleague reviewing my code and he had a comment on a factory class I created. It's very simple: ...
1
vote
1answer
106 views

Makes a navbar for a website with object oriented php

I do this as sort of hobby and want to no if I can improve. This is a simplified version of my code that normal works with bootstrap classes and id's. At the bottom there is the input of the classes. ...
1
vote
1answer
50 views

Feedback Request on Title Capitalization Function Converted From JavaScript to PHP

I have a function in JavaScript that converts a string value to title case using APA style: ...
1
vote
0answers
167 views

Reading 100,000 of data with loop and usort is too slow [closed]

The below code is meet to solve the question posted here https://stackoverflow.com/questions/61302983/in-a-meetup-schedule-algorithm-to-get-unique-and-available-date, but I can't post it as a solution ...
1
vote
1answer
508 views

My method of php ajax product filter with pagination

After a few weeks of searching and learning ajax, pagination php, product filter, I created ajax php product filter with pagination. 1. index.php ...
0
votes
1answer
40 views

concatenation of HTML from return functions

My controller is looking something like this. Each of the methods called generate some HTML. The concatenated HTML variable gives the final render of the page Is there a better way to generate my ...
1
vote
1answer
219 views

Codeigniter 3 CMS (blogging) application

I am working on a basic blog application with Codeigniter 3.1.8 and Bootstrap 4. The application has users (authors) and posts (articles). Every article: has an author, belongs to a category, has a ...
5
votes
3answers
358 views

Dynamic insert function for PDO (for any case)

I created a dynamic insert function for PDO. It does work, but I want to be sure that it is secure and well coded. ...
5
votes
1answer
215 views

PHP OOP MVC structure

I am quite new to the MVC concept. I already know how to program object-orientated from other languages like C++ or Java. I have implemented a little login system for test purpose. I am not sure if my ...
11
votes
2answers
4k views

Fizz Buzz interview question code

Reading Jeff Atwood's "Why Can't Programmers.. Program?" led me to think that almost all of the solutions would not be something I would want in my own code-base. The Fizz Buzz program specification ...

1
3 4
5
6 7
84